File tree 1 file changed +19
-15
lines changed
src/main/java/com/fishercoder/solutions 1 file changed +19
-15
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
3
/**
4
+ * 633. Sum of Square Numbers
5
+ *
4
6
* Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.
5
7
6
8
Example 1:
13
15
Output: False
14
16
*/
15
17
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 ;
30
22
}
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 ;
31
36
}
32
- return false ;
33
37
}
34
38
}
You can’t perform that action at this time.
0 commit comments