633 Sum of Square Numbers
Problem
Input: 5
Output: True
Explanation: 1 * 1 + 2 * 2 = 5Input: 3
Output: FalseSolutions
class Solution {
public boolean judgeSquareSum(int c) {
HashSet<Long> nums = new HashSet<>();
for (int i = 0; i <= Math.sqrt(c); i ++) {
nums.add((long)i*i);
if (nums.contains((long)(c - i*i))) {
return true;
}
}
return false;
}
}Last updated