【双指针】633. 平方数之和
题解
代码
class Solution {
public:
bool judgeSquareSum(int c) {
long low = 0;
long high = int(sqrt(c));
while(low <= high)
{
long sumOf = low * low + high * high;
if(sumOf == c)
{
return true;
}
else if(sumOf < c)
{
low += 1; // 指针下移 寻找更大的数字
}
else
{
high -= 1; // 指针左移 寻找更小的数字
}
}
return false;
}
};