美文网首页程序员
633. Sum of Square Numbers

633. Sum of Square Numbers

作者: namelessEcho | 来源:发表于2017-09-26 16:37 被阅读0次

two sum 的换壳题 ,只是把原有在数组有序下相加为定值变成了平方的和相加为定值。

class Solution {
    public boolean judgeSquareSum(int c) {
        int hi = (int)Math.sqrt(c);
        int lo = 0;
        while(lo<=hi)
        {
            int sum = hi*hi+lo*lo;
            if(sum==c)
                return true;
            else if (sum<c)
                lo++;
            else
                hi--;
                
        }
        return false;
    }
}

相关文章

网友评论

    本文标题:633. Sum of Square Numbers

    本文链接:https://www.haomeiwen.com/subject/mtzsextx.html