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 - 平方数 ...
随机推荐
- AOP理解,待细看
http://jinnianshilongnian.iteye.com/blog/1474325
- intellij idea build时出现Artifact contains illegal characters的解决
此处无法创建是因为Artifact的命名为大小写混合,将大写改为小写即可正常创建
- HTML5 Audio/Video 标签属性与事件
chrom 只测试过部分属性,均正常,兼容性未测试: 标签属性:src:音乐的URLpreload:预加载autoplay:自动播放loop:循环播放controls:浏览器自带的控制条 1 标签属性 ...
- MySQL复制:主从和双主配置
对比Replication和Cluster 应用层中间件的负载均衡 异步的复制过程 MySQL官方使用Replication场景
- UML类图(二)----------类与类之间的关系之关联(聚合与组合)
类与类之间的关系: 在软件系统中,类并不是孤立存在的,类与类之间存在各种关系,对于不同类型的关系,UML提供了不同的表示方式. 1. 关联关系 关联(Association)关系是类与类之 ...
- zoj3988 二分图匹配
给一个数组,对于每两个数加起来为素数那么就是一个集合,求不超过k个集合的最多数是多少 解法:二分图匹配,先打素数筛,预处理边集,匹配完之后分两种情况k>匹配数,那么可以直接输出匹配数*2,否则可 ...
- uva 10453 dp/LCS变形
https://vjudge.net/problem/UVA-10453 给出一个字符串,问最少添加几个字符使其变为回文串,并输出任意一种答案.就是一个类似于LCS的题目,而且简化了一下,只会出现三种 ...
- Java 简单图片截取
package cn.byref.demo.image; import java.awt.Rectangle; import java.awt.image.BufferedImage; import ...
- CentOS7下Tomcat启动特别慢【有效解决】
多次亲测! 很简单,记录保存一下: 编辑 $JAVA_HOME/jre/lib/security/java.security 文件, 找到 securerandom.source=file:/dev/ ...
- eclipse配置lombok
原文:http://wsj356428476.iteye.com/blog/1655032 1.下载Lombok.jar https://projectlombok.org/ 2.运行Lombok.j ...