LeetCode 633 Sum of Square Numbers
来源:互联网 发布:封面制作软件ios 编辑:程序博客网 时间:2024/06/08 17:04
题目:
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: 5Output: TrueExplanation: 1 * 1 + 2 * 2 = 5
Example 2:
Input: 3Output: False题目链接
题意:
给一个非负的整数c,判断是否存在两个整数a,b满足a2 + b2 = c。
c是非负的,所以a和b的取值可以为0,所以a和b取值应该是[0, sqrt(c)],从0到sqrt(c)枚举一遍,假如c-a*a开平方后可以整除1,那么说明此时的a,b满足条件。
代码如下:
class Solution {public: bool judgeSquareSum(int c) { int temp = sqrt(c); for (int i = 0; i <= temp; i ++) { int j = c - i * i; if (fmod(sqrt(j), 1.00) != 0) { continue; } return true; } return false; }};
阅读全文
0 0
- Leetcode 633 Sum of Square Numbers
- LeetCode 633 Sum of Square Numbers
- leetcode[Sum of Square Numbers]
- LeetCode 633 : Sum of Square Numbers(python)
- [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
- LeetCode 633. Sum of Square Numbers
- 【LeetCode】Sum of Square Numbers 解题报告
- leetcode 633. Sum of Square Numbers
- leetcode 633. Sum of Square Numbers
- [LeetCode]633. Sum of Square Numbers
- Sum of Square Numbers
- 【leetcode】633. Sum of Square Numbers(Python & C++)
- leetcode 633. Sum of Square Numbers 二分查找
- 2017.12.25 LeetCode 633. Sum of Square Numbers【思维枚举】
- PHP错误类型及屏蔽方法
- 达内云笔记(三)模式初涉
- stm32 使用外部时钟的注意事项(jlink调试输出无信息)
- 爬取房天下(全站)
- tomcat 集群 session复制共享 redis实战版本
- LeetCode 633 Sum of Square Numbers
- poj2063 Investment(完全背包)
- hdu6201transaction transaction transaction(最长路spfa vector模板)
- 0911 Oracle基本概念
- 3Layer
- Taints and Tolerations
- 电子之电容测试标准
- eclipse配置生成.h和.so文件过程
- 剑指offer——42.和为sum的两个数字