双指针之平方数之和

阅读 41

2022-01-31

每日一题ing,今天是个medium题633. Sum of Square Numbers

class Solution {
public:
    bool judgeSquareSum(int c) {
        long long i=0,j=sqrt(c);
        while(i<=j){
            long long temp=i*i+j*j;
            if(temp==c){
                return true;
            }
            if(temp>c){
                j--;
            }
            else{
                i++;
            }
        }
        return false;
    }
};

相关推荐

精彩评论(0)

0 0 举报