用开方的思想来解题。

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. UVA 11029 || Lightoj 1282 Leading and Trailing 数学

    Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...

  2. svg_path

    1. path 的 d属性中,M的大/小写貌似不影响图形显示效果(至少现在[20160108]我测试下来是这样[chrome 版本 47.0.2526.80 m]):L/H/V 的大小写 是影响图形显 ...

  3. OpenStack with Opendaylight Part 1: Intro to Pipeline

    Using Vagrant to create vm nodes; devstack to start openstack using Opendaylight as ML2. Openstack w ...

  4. 中安装rackspace private cloud --6 Deployment rpc

    运行ansible playbook安装之前的准备工作: Perform deployment host initial setup Build containers on target hosts ...

  5. hadoop环境搭建(linux单机版)

    一.在Ubuntu下创建hadoop用户组合hadoop用户 1.创建hadoop用户组      addgroup hadoop 2.创建hadoop用户      adduser -ingroup ...

  6. 搜索5--noi1700:八皇后问题

    搜索5--noi1700:八皇后问题 一.心得 二.题目 1700:八皇后问题 查看 提交 统计 提问 总时间限制:  10000ms 内存限制:  65536kB 描述 在国际象棋棋盘上放置八个皇后 ...

  7. linux 处理端口

    1.查看8080端口是否被占用: netstat -anp | grep 8080 2.查看占用8080端口的进程:fuser -v -n tcp 8080 3.杀死占用8080端口的进程: kill ...

  8. SVN的安装和使用

    1.安装 下载SVN,一直默认安装 安装成功后,配置环境变量path=C:\Program Files\TortoiseSVN\bin 验证SVN安装是否成功:adb -help 或 adb -ver ...

  9. IDEA Tomcat服务器 更新.jsp时,页面刷新无法同步修改

    这是因为在配置服务时没有配置好: on frame deactivation部分

  10. SQL多表联查总结

    交叉连接:(不常用)返回两个表的笛卡尔乘积(也即全组合排列)中符合查询条件的数据行. 内连接返回连接表中符合连接条件和查询条件的数据行. 左外连接返回符合连接条件和查询条件(即:内连接)的数据行,且还 ...