633. Sum of Square Numbers
2017-08-30 08:37
253 查看
题目:
Given a non-negative integer
that a2 + b2 = c.
Example 1:
Example 2:
思路:
本题思路是真的简单,只需要循环遍历0-sqrt(c)的整数,判断是否存在符合要求的两个整数。
代码:
class Solution {
public:
bool judgeSquareSum(int c) {
for(int a=0;a<=sqrt(c);a++)
{
if(sqrt(c-a*a)-int(sqrt(c-a*a))==0.0)
return true;
}
return false;
}
};
Given a non-negative integer
c, your task is to decide whether there're two integers
aand
bsuch
that a2 + b2 = c.
Example 1:
Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5
Example 2:
Input: 3 Output: False
思路:
本题思路是真的简单,只需要循环遍历0-sqrt(c)的整数,判断是否存在符合要求的两个整数。
代码:
class Solution {
public:
bool judgeSquareSum(int c) {
for(int a=0;a<=sqrt(c);a++)
{
if(sqrt(c-a*a)-int(sqrt(c-a*a))==0.0)
return true;
}
return false;
}
};
相关文章推荐
- 633. Sum of Square Numbers 平方数之和 看一个数是否能够有两个平方数组成
- [leetcode]633. Sum of Square Numbers
- [LeetCode]633. Sum of Square Numbers
- 633. Sum of Square Numbers
- 633. Sum of Square Numbers。
- 633. Sum of Square Numbers (数学)
- 633. Sum of Square Numbers
- 633. Sum of Square Numbers
- LeetCode 633. Sum of Square Numbers
- leetcode 633. Sum of Square Numbers 二分查找+勾股定理
- [leetcode]633. Sum of Square Numbers
- leetcode 633. Sum of Square Numbers
- 633. Sum of Square Numbers
- 633. Sum of Square Numbers标题
- [Leetcode] 633. Sum of Square Numbers 解题报告
- LeetCode 633. Sum of Square Numbers
- LeetCode 633. Sum of Square Numbers
- leetcode 633. Sum of Square Numbers
- 【leetcode】633. Sum of Square Numbers(Python & C++)
- 633. Sum of Square Numbers