[力扣] 算法 633 (C++)

633. 平方数之和

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

发表评论