Given a non-negative integer c, your task is to decide whether there’re two integers a and b such that a2 + b2 = c.
Example 1:
1 |
Input: 5 |
Example 2:
1 |
Input: 3 |
題意
给一个数字 c,判断是否满足 a^2 + b^2 = c
思路
从 0 到 sqrt(c)之间进行遍历,检测剩下的数开方后是不是整数。
代码
1 |
boolean judgeSquareSum(int c) { |
近期评论