Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5b05d77

Browse files
refactor 633
1 parent 8d106db commit 5b05d77

File tree

1 file changed

+19
-15
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+19
-15
lines changed
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.fishercoder.solutions;
22

33
/**
4+
* 633. Sum of Square Numbers
5+
*
46
* Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.
57
68
Example 1:
@@ -13,22 +15,24 @@
1315
Output: False
1416
*/
1517
public class _633 {
16-
public boolean judgeSquareSum(int c) {
17-
if (c < 0) {
18-
return false;
19-
}
20-
int left = 0;
21-
int right = (int) (Math.sqrt(c));
22-
while (left <= right) {
23-
int curr = left * left + right * right;
24-
if (curr > c) {
25-
right--;
26-
} else if (curr < c) {
27-
left++;
28-
} else {
29-
return true;
18+
public static class Solution1 {
19+
public boolean judgeSquareSum(int c) {
20+
if (c < 0) {
21+
return false;
3022
}
23+
int left = 0;
24+
int right = (int) (Math.sqrt(c));
25+
while (left <= right) {
26+
int curr = left * left + right * right;
27+
if (curr > c) {
28+
right--;
29+
} else if (curr < c) {
30+
left++;
31+
} else {
32+
return true;
33+
}
34+
}
35+
return false;
3136
}
32-
return false;
3337
}
3438
}

0 commit comments

Comments
 (0)