注意这里遍历要用long long ,用int会溢出。
class Solution {
public:
bool judgeSquareSum(int c) {
bool flag = false;
int tmp;
for(long long i = 0; i * i <= c; i++){
if(i * i == c){
flag = true;
break;
}else{
tmp = c - i * i;
int j = sqrt(tmp);
if(i * i + j * j == c){
flag = true;
break;
}
}
}
return flag;
}
};