File tree Expand file tree Collapse file tree 1 file changed +19
-15
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +19
-15
lines changed Original file line number Diff line number Diff line change 11package 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:
1315 Output: False
1416 */
1517public 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}
You can’t perform that action at this time.
0 commit comments