Skip to content

Commit a306cd2

Browse files
Solutions
1 parent d56b319 commit a306cd2

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class Solution {
2+
public bool CheckPowersOfThree(int n) {
3+
while (n > 0) {
4+
if (n % 3 > 1) {
5+
return false;
6+
}
7+
n /= 3;
8+
}
9+
return true;
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
impl Solution {
2+
pub fn check_powers_of_three(n: i32) -> bool {
3+
let mut n = n;
4+
while n > 0 {
5+
if n % 3 > 1 {
6+
return false;
7+
}
8+
n /= 3;
9+
}
10+
true
11+
}
12+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
impl Solution {
2+
pub fn beauty_sum(s: String) -> i32 {
3+
let mut ans = 0;
4+
let n = s.len();
5+
let s: Vec<char> = s.chars().collect();
6+
7+
for i in 0..n {
8+
let mut cnt = vec![0; 26];
9+
for j in i..n {
10+
cnt[s[j] as usize - 'a' as usize] += 1;
11+
let mut mi = 1000;
12+
let mut mx = 0;
13+
for &v in &cnt {
14+
if v > 0 {
15+
mi = mi.min(v);
16+
mx = mx.max(v);
17+
}
18+
}
19+
ans += mx - mi;
20+
}
21+
}
22+
ans
23+
}
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function beautySum(s: string): number {
2+
let ans = 0;
3+
for (let i = 0; i < s.length; ++i) {
4+
const cnt = new Map();
5+
for (let j = i; j < s.length; ++j) {
6+
cnt.set(s[j], (cnt.get(s[j]) || 0) + 1);
7+
const t = Array.from(cnt.values());
8+
ans += Math.max(...t) - Math.min(...t);
9+
}
10+
}
11+
return ans;
12+
}

0 commit comments

Comments
 (0)