用开方的思想来解题。

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的更多相关文章

  1. [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 ...

  2. Leetcode633.Sum of Square Numbers平方数之和

    给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 示例2: 输入: 3 ...

  3. LeetCode633. Sum of Square Numbers(双指针)

    题意:给定一个非负整数c,确定是否存在a和b使得a*a+b*b=c. class Solution { typedef long long LL; public: bool judgeSquareSu ...

  4. C#刷遍Leetcode面试题系列连载(4) No.633 - 平方数之和

    上篇文章中一道数学问题 - 自除数,今天我们接着分析 LeetCode 中的另一道数学题吧~ 今天要给大家分析的面试题是 LeetCode 上第 633 号问题, Leetcode 633 - 平方数 ...

随机推荐

  1. C#加密解密DES字符串<转>

    using System; using System.Collections.Generic; using System.Text; using System.Security.Cryptograph ...

  2. lnmp安装exif扩展

    lnmp安装exif扩展 1.找到位置 cd /usr/local/lnmp1.4-full/src 2.解压php sudo bzip2 -d php-5.6.31.tar.bz2 sudo tar ...

  3. numpy nonzero与isnan

    nonzero 直接看例子: In [83]: x = np.array([[1,0,0], [0,2,0], [1,1,0]]) In [84]: x.shape Out[84]: (3L, 3L) ...

  4. FreeTDS-SQL Server在linux和unix下的免费驱动

    微软为MS SQL Server的连接和使用提供了很好的 驱动和 文档. 不幸的是,那只能在windows操作系统上使用. 所以对于Linux或者Unix,您需要寻找不同的方法来连接MS SQL Se ...

  5. Spring Cloud实战微服务入门

    1.spring cloud是什么? 是一个快速构建分布式系统的工具集,构建于Spring Boot之上 2.spring cloud 的特点 约定优于配置 开箱即用.快速启动 适用于各种环境 轻量级 ...

  6. PhpSpreadsheet如何读取excel文件

    PhpSpreadsheet如何读取excel文件 一.总结 一句话总结:万能的百度,直接搜代码就好,绝对有,毕竟github上面4000+的关注,说明很多人用了这个,使用照着demo倒是异常简单 二 ...

  7. Mssql 跨域查询

    有数据库test1和数据库test2.其中test1中有表 table1.table2:test2 中有表 table1.三个表的字段都为为:id.xingming.shijian.shuliang. ...

  8. ServlertContext

    1.ServletContext代表着整个JavaWeb应用,每个项目只有唯一的ServletContext的实例. 2.生命周期 服务器启动时创建 服务器关闭时销毁 3.获取ServletConte ...

  9. python虚拟开发环境搭建(virtualenv和virtualenvwrapper)

    虚拟开发环境的搭建 (0) 搭建虚拟环境的意义 使不同的开发环境独立 环境升级不影响其他开发环境,也不影响全局 防止包管理的混乱 (1) 指定 虚拟环境的创建目录 环境变量设置 创建 WORKON_H ...

  10. 利用HTML5开发Android笔记(下篇)

    资源来自于www.mhtml5.com 杨丰盛老师成都场的PPT分享 一个很简明的demo 可以作为入门基础 学习的过程中做了点笔记 整理如下 虽然内容比较简单 但是数量还是比较多的 所以分了3篇 ( ...