633. Sum of Square Numbers
题目就是非负正数 c,是否可以写成c**2 = a**2+b**2
1、缩写范围,因为是平方和,所以a,b两个数一个在c的平方根内
2、循环得出另一个数的平方
3、这里用到一个小技巧,一个数的平方开方取整在平方是否和原来相等,若相等则存在
4、例如:
c=10 i=0 m=10 int(math.sqrt(m))=3 再平方等于9不等于10
i=1 m=9 int(math.sqrt(m))=3 再平方等于9
- class Solution(object):
- def judgeSquareSum(self, c):
- """
- :type c: int
- :rtype: bool
- """
- length = int(math.sqrt(c))
- for i in range(length+1):
- m = c-i**2
- if int(math.sqrt(m))**2==m:
- return True
- return False
633. Sum of Square Numbers相关推荐
- LeetCode 633. 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 ...
- lintcode: Check Sum of Square Numbers
Check Sum of Square Numbers Given a integer c, your task is to decide whether there're two integers ...
- 633.平方数之和(Sum of Square Numbers)
题目描述 给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 示例2: 输 ...
- LeetCode633 | Sum of Square Numbers (Easy)
题目地址(633. 平方数之和) https://leetcode-cn.com/problems/sum-of-square-numbers/ 题目描述 给定一个非负整数 c ,你要判断是否存在两个 ...
- C#LeetCode刷题之#633-平方数之和( Sum of Square Numbers)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3885 访问. 给定一个非负整数 c ,你要判断是否存在两个整数 ...
- LeetCode 985 Sum of Even Numbers After Queries 解题报告
题目要求 We have an array A of integers, and an array queries of queries. For the i-th query val = queri ...
- [CF1598G]The Sum of Good Numbers
The Sum of Good Number 题解 这种高精加法哈希比较的题真的很臭呀,赛后一群人在那里卡模数,真的吐了 我们考虑如何快速比较两个大整数的和,显然,哈希是一种很好的方法,所以我们可以将 ...
- Sum of Even Numbers After Queries
Solution: 转载于:https://www.cnblogs.com/Julietma/p/10414394.html
- LeetCode | 我的LeetCode之旅(持续更新ing)
我的LeetCode算法之旅,记录每天学习LeetCode的进程目录. 算法思想 1.双指针 LeetCode167 | 有序数组的 Two Sum 167.Two Sum II - Input ar ...
最新文章
- 忽悠神经网络指南:教你如何把深度学习模型骗得七荤八素
- 2016 大连网赛---Different GCD Subarray Query(GCD离散+树状数组)
- 还在网上找Demo?这个Java项目真香!
- Docker 的日志相关整理
- 华为徐直军:以持续创新加快数字化发展
- python解析html的库_python解析html开发库pyquery使用方法
- HTML项目代码编写规范
- 有谁做过在C# winform里,显示3D max文件的呢?请赐教了。
- Java动态规划走金字塔_【动态规划基础】数字金字塔
- java jframe 图标_java怎么修改jframe图标?
- 12张大数据图看看2016年世界各地发生大事件!
- 官宣!AutoSec第六届中国汽车网络安全周火热来袭,10大特色首度曝光!1000+精准专业观众、60+OEM竞相参与
- 找到一个电信代理服务器~
- 敏捷开发 敏捷个人_在敏捷2013中寻找答案
- encrypted勒索病毒攻击nas服务器,服务器中了勒索病毒解密数据恢复
- 对冲基金母基金(FoHF)
- 【Unity Shader】(2)半兰伯特模型 构建光照
- 黑群晖USB直连计算机,群辉(黑群辉)自动/定时备份U盘数据到硬盘内--原创
- 概念整理ia32/x86/amd64/ia64/arm64
- 要matlab标定数据做双目相机矫正OpenCV C++