leetcode 633+は、1つの数が2つの数の二乗和であるか否かを判断する

350 ワード

https://leetcode.com/problems/sum-of-square-numbers/description/
class Solution {
public:
    bool judgeSquareSum(int c) {
        int limit = sqrt(c);
        for(int i=0; i<=limit; i++){
            double test = sqrt(c-i*i);
            if(test- int(test)==0) return true;
        }
        return false;
    }
};