题目
思路
双指针解法left从0开始,right从sqrt(c)开始。
然后判断收缩指针。
代码语言:javascript复制class Solution {
public:
bool judgeSquareSum(int c) {
long long left = 0, right = sqrt(c);
while (left <= right) {
long long a = left * left, b = right * right;
if (a b == c) return true;
else if (a b < c) {
left ;
}
else {
right--;
}
}
return false;
}
};