leetcode633
用开方的思想来解题。
bool judgeSquareSum(int c) {
int h = pow(c, 0.5);
for (int i = ; i <= h; i++)
{
double left = pow(c - pow(i, ), 0.5);
if (left - int(left) == 0.0)
{
return true;
}
}
return false;
}
补充一个phthon的实现,使用双指针思想:
class Solution:
def judgeSquareSum(self, c: int) -> bool:
i=0
j=int(c ** 0.5)
while i<=j:
target = i*i +j*j
if target==c:
return True
elif target>c:
j-=1
else:
i+=1 return False
leetcode633的更多相关文章
- [Swift]LeetCode633. 平方数之和 | Sum of Square Numbers
Given a non-negative integer c, your task is to decide whether there're two integers a and b such th ...
- Leetcode633.Sum of Square Numbers平方数之和
给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 示例2: 输入: 3 ...
- LeetCode633. Sum of Square Numbers(双指针)
题意:给定一个非负整数c,确定是否存在a和b使得a*a+b*b=c. class Solution { typedef long long LL; public: bool judgeSquareSu ...
- C#刷遍Leetcode面试题系列连载(4) No.633 - 平方数之和
上篇文章中一道数学问题 - 自除数,今天我们接着分析 LeetCode 中的另一道数学题吧~ 今天要给大家分析的面试题是 LeetCode 上第 633 号问题, Leetcode 633 - 平方数 ...
随机推荐
- php的http数据传输get/post...
php的http数据传输get/post... 一般有:file_get_contents,curl,fsockopen.... 下面介绍fsockopen: //构造要post的字符串 $argv ...
- 常用的CDN 链接 http://cdn.code.baidu.com/ http://www.bootcdn.cn/
http://cdn.code.baidu.com/ http://developer.baidu.com/wiki/index.php?title=docs/cplat/libs ★新浪CDN,感觉 ...
- 为mac编写swift脚本
代码示例: #!/usr/bin/env xcrun swift print("Hello World") 可以用Sublime Text编写,安装Swift包后有语法着色功能.然 ...
- 如何关闭 window10 自带的杀毒软件
打开运行,快捷键[win+R],输入[ gpedit.msc],点击确定 在打开的组策略窗口中,依次展开计算机配置>管理模板>Windows组件,选择[windows组件]中的window ...
- memset函数用法及注意事项
头文件 #include<cstring>// or #include<memory.h> ------------------------------------------ ...
- Spring_总结_04_高级配置(三)_处理歧义
一.前言 本文承接上一节:Spring_总结_04_高级配置(二)之条件注解@Conditional 我们前面装配bean时,在Spring容器中,都是只有一个bean能匹配所需的结果. 如果有多个b ...
- 初识Linux--虚拟机下安装Ubuntu16
最近接收到任务,说是下半年可能要搞全文检索.听到后顿时炸锅了,一方面是对新技术的兴奋,另一方面,我TM连Linux都不会玩,怎么搞全文检索.怀揣着对开源世界的无线向往(恐惧),我决定试水Linux. ...
- 应该是实例化对象的没有对属性赋值时,自动赋值为null,但不是空指针对象引用
此时会输出两个null. Users类的实例是myUsers,但是由于javabean的作用范围是page,所以前面页面传送的javabean的设置的属性全部不能接收到.所以对象myUsers属性为自 ...
- hdoj-1276-士兵队列训练问题(队列模拟)
题意: 新兵蛋子按照两种报数规则报数: 1.1212报数,2出队 2.123123报数,3出队 没报完一轮,检查人数,不大于3,over 略坑,必须每报完一轮检查人数,最初,按照12两种顺序报完检查人 ...
- listening 1
It was regrettable that such great issues had to be the thrust and parry of a general election. But ...