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