633. Sum of Square Numbers
来源:互联网 发布:sql函数的种类 编辑:程序博客网 时间:2024/05/19 00:48
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:
Input: 5
Output: True
Explanation: 1 * 1 + 2 * 2 = 5
Example 2:
Input: 3
Output: False
判断一个数c是否能由两个平方数相加得到。使用暴力的方法,令a从0到sqrt(c),判断c-a^2是不是平方数即可。
代码:
class Solution{public: bool judgeSquareSum(int c) { for(int i = 0; i <= sqrt(c); ++i) { double d = sqrt(c-i*i); if(d == int(d)) { return true; } } return false; }};
阅读全文
0 0
- 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。
- 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
- 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 (数学)
- java8新特性--概览
- HDU 1175 连连看
- 【Unity学习笔记】——基础篇:小地图制作③
- 8.3吝啬SAT问题
- Linux常用命令(2)-
- 633. Sum of Square Numbers
- LeetCode.14. Longest Common Prefix(最长公共前缀)
- Html、CSS、JavaScript三个都是什么【2017.7.9】
- 从权限到shiro框架
- 单片机实验五
- java学习笔记:Java语法基础2(循环,函数,重载,数组,方法)
- dump 源码
- 2.5 程序流程控制
- ROS机器人操作系统的安装、配置与初级教程 11