We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f49dec1 commit 9c667dcCopy full SHA for 9c667dc
scripts/algorithms/S/Sum of Square Numbers/Sum of Square Numbers.java
@@ -1,20 +1,21 @@
1
+// Runtime: 4 ms (Top 55.1%) | Memory: 39.57 MB (Top 27.7%)
2
+
3
class Solution {
4
public boolean judgeSquareSum(int c) {
- long left=0;
- long right=(int)Math.sqrt(c);
5
- while(left<=right)
6
- {
7
- if((left*left+right*right)==c)
+ long a = 0;
+ long b = (long) Math.sqrt(c);
8
+ while(a<=b){
9
+ if(((a*a) + (b*b)) == c){
10
return true;
- else
11
- if((left*left+right*right)>c)
12
- right=right-1;
13
14
- left=left+1;
15
}
16
-
+ else if((((a*a)+(b*b)) < c)){
+ a++;
+ }
+ else{
+ b--;
17
18
19
return false;
20
-}
21
+}
0 commit comments