```
public class Solution {
public boolean judgeSquareSum(int c) {
int root = (int) Math.sqrt(c);
int left = 0, right = root;
while (left <= right) {
if (left * left + right * right < c) {
left++;
}
else if (left * left + right * right > c) {
right--;
}
else {
return true;
}
}
return false;
}
}
```