We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 382dd32 commit aab9d0bCopy full SHA for aab9d0b
scripts/algorithms/S/Sum of Square Numbers/Sum of Square Numbers.js
@@ -1,11 +1,15 @@
1
+// Runtime: 52 ms (Top 89.65%) | Memory: 42.70 MB (Top 31.03%)
2
+
3
var judgeSquareSum = function(c) {
- let a = 0;
- 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
+};
15
- while (a <= b) {
- const sum = a ** 2 + b ** 2;
- if (sum === c) return true;
- sum > c ? b -= 1 : a += 1;
- }
- return false;
-};
0 commit comments