Skip to content

Commit d56b319

Browse files
Solutions
1 parent 55d1fdb commit d56b319

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
impl Solution {
2+
pub fn is_power_of_three(mut n: i32) -> bool {
3+
while n > 2 {
4+
if n % 3 != 0 {
5+
return false;
6+
}
7+
n /= 3;
8+
}
9+
n == 1
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @param {number} n
3+
* @return {boolean}
4+
*/
5+
var isPowerOfThree = function (n) {
6+
return n > 0 && 1162261467 % n == 0;
7+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
impl Solution {
2+
pub fn is_power_of_three(mut n: i32) -> bool {
3+
n > 0 && 1162261467 % n == 0
4+
}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function isPowerOfThree(n: number): boolean {
2+
return n > 0 && 1162261467 % n == 0;
3+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number[]} arr
3+
* @return {boolean}
4+
*/
5+
var canMakeArithmeticProgression = function (arr) {
6+
const n = arr.length;
7+
const a = Math.min(...arr);
8+
const b = Math.max(...arr);
9+
10+
if ((b - a) % (n - 1) !== 0) {
11+
return false;
12+
}
13+
14+
const d = (b - a) / (n - 1);
15+
const s = new Set(arr);
16+
17+
for (let i = 0; i < n; ++i) {
18+
if (!s.has(a + d * i)) {
19+
return false;
20+
}
21+
}
22+
return true;
23+
};

0 commit comments

Comments
 (0)