Skip to content

Commit aab9d0b

Browse files
committed
Runtime: 52 ms (Top 89.65%) | Memory: 42.70 MB (Top 31.03%)
1 parent 382dd32 commit aab9d0b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

scripts/algorithms/S/Sum of Square Numbers/Sum of Square Numbers.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
// Runtime: 52 ms (Top 89.65%) | Memory: 42.70 MB (Top 31.03%)
2+
13
var judgeSquareSum = function(c) {
2-
let a = 0;
3-
let b = Math.sqrt(c) | 0;
4+
if (c === 0) {
5+
return true
6+
}
7+
for (let a = 0; a*a < c; a++) {
8+
let b = Math.sqrt(parseFloat(c-a*a));
9+
if (b - Math.round(b) === 0) {
10+
return true;
11+
}
12+
}
13+
return false
14+
};
415

5-
while (a <= b) {
6-
const sum = a ** 2 + b ** 2;
7-
if (sum === c) return true;
8-
sum > c ? b -= 1 : a += 1;
9-
}
10-
return false;
11-
};

0 commit comments

Comments
 (0)