633. 平方数之和 Posted on 2018-08-30 | In leetcode Words count in article: 133 | Reading time ≈ 1 题目给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a^2 + b^2 = c。 示例1:123输入: 5输出: True解释: 1 * 1 + 2 * 2 = 5 示例2:12输入: 3输出: False 解法解法一:不好说 Java1234567891011121314151617181920class Solution { public boolean judgeSquareSum(int c) { if (c < 0) { return false; } int mid = (int) Math.sqrt(c); int left = 0; int right = mid; while (left <= right ) { if (c == left * left + right * right) { return true; } else if (c > left * left + right * right) { left++; } else { right--; } } return false; }}