Sum of Square Numbers
Given a non-negative integer c, your task is to decide whether there’re two integers a and b such that a2 + b2 = c.
时间复杂度:O(n)
空间复杂度:O(1)
public boolean judgeSquareSum(int c) {
int hi = (int)Math.sqrt(c);
int lo = 0;
while(lo <= hi) {
int temp = lo * lo + hi * hi;
if(temp == c){
return true;
}else if(temp > c){
hi--;
}else{
lo++;
}
}
return false;
}