CS-Notes icon indicating copy to clipboard operation
CS-Notes copied to clipboard

发现一点小错误

Open hello-ikun opened this issue 4 years ago • 3 comments

原题链接

class Solution {
public:
    bool judgeSquareSum(int c) {
        if(c<0) return false;
        int i=0,j=(int)sqrt(c);
        while(i<=j)
        {
            // long powSum=i*i+j*j;//不建议使用pow 会出现 上溢
            // if (powSum==target) return true;
            // else if(powSum>target) --j;
            // else ++i;
            if(c-i*i==j*j) return true;
            else if(c-i*i<j*j)--j;
            else ++i;
        }
        return false;
    }
};

这样来写的 话 就可以了 会出现 溢出的情况 希望作者更细一下

hello-ikun avatar Nov 17 '21 09:11 hello-ikun

是的,溢出的问题 +1 建议修改一下

fxslltfxl avatar Nov 18 '21 07:11 fxslltfxl

是的,溢出的问题 +1 建议修改一下

害 问题不大

hello-ikun avatar Nov 18 '21 08:11 hello-ikun

11

ljqczlm avatar Dec 30 '21 08:12 ljqczlm