class Solution {
public boolean judgeSquareSum(int c) {
for (int l = 0, r = (int) Math.sqrt(c); l <= r; l++){
while (r >= 0 && l * l + r * r > c) r--;
if (l * l + r * r == c) return true;
}
return false;
}
}