Easy
Simple two pinters记住只需要遍历到sqrt(c)就可以了.
class Solution {
public boolean judgeSquareSum(int c) {
int i = 0;
int j = (int) Math.sqrt(c);
while (i <= j){
int squareSum = i*i + j*j;
if (squareSum == c){
return true;
} else if (squareSum > c){
j--;
} else {
i++;
}
}
return false;
}
}