JAVA AC solution


  • 0
    W
        public boolean judgeSquareSum(int c) {
            if (c < 0) return false;
            long left = 0L;
            long right = (long) Math.sqrt(c);
            while (left <= right) {
                long sum = left * left + right * right;
                if (sum > c) {
                    right--;
                } else if (sum < c) {
                    left++;
                } else {
                    return true;
                }
            }
            return false;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.