[leetcode]633. Sum of Square Numbers

双指针比较简单的应用,搜索范围要注意

public boolean judgeSquareSum(int c) {
        /*
        双指针,搜索范围是0到sqrt(c)
         */
        if (c<0) return false;
        int left = 0;
        int right = (int)Math.sqrt(c);
        while (left<=right)
        {
            int cur = left*left+right*right;
            if (c>cur) left++;
            else if (c<cur) right--;
            else return true;
        }
        return false;
    }
原文地址:https://www.cnblogs.com/stAr-1/p/8485164.html