程式語言 - LeetCode - CPP - 633. Sum of Square Numbers



題目:


解答:

class Solution {
public:
    bool judgeSquareSum(int c) {
        if (c == 0) {
            return true;
        }

        for (long i = 1; i * i <= c; ++i) {
            long m = sqrt(c - i * i);

            if (i * i + m * m == c) {
                return true;
            }
        }

        return false;
    }
};