We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bb3b717 commit dbd7d34Copy full SHA for dbd7d34
src/leetcode/SumofSquareNumbers.java
@@ -0,0 +1,42 @@
1
+package leetcode;
2
+
3
+public class SumofSquareNumbers {
4
5
+ public static void main(String[] args) {
6
+ // TODO Auto-generated method stub
7
8
+ }
9
10
+ public boolean judgeSquareSum(int c) {
11
+ int limit = helper(c);
12
+ int r =limit;
13
+ for(int i=0; i<=limit && r>=i;){
14
+ int sum =i*i + r*r;
15
+ if(sum==c){
16
+ return true;
17
+ }else if(sum<c){
18
+ i++;
19
+ }else{
20
+ r--;
21
22
23
24
+ return false;
25
26
27
+ public int helper(int x){
28
+ if(x<=1) return x;
29
+ int start=0, end=x;
30
+ while(start<=end) {
31
+ int mid = start + (end-start)/2;
32
+ if(x/mid==mid)
33
+ return mid;
34
+ else if(x/mid<mid)
35
+ end = mid-1;
36
+ else
37
+ start = mid+1;
38
39
+ return end;
40
41
42
+}
0 commit comments