题目就是非负正数 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

  1. class Solution(object):
  2. def judgeSquareSum(self, c):
  3. """
  4. :type c: int
  5. :rtype: bool
  6. """
  7. length = int(math.sqrt(c))
  8. for i in range(length+1):
  9. m = c-i**2
  10. if int(math.sqrt(m))**2==m:
  11. return True
  12. return False

633. Sum of Square Numbers相关推荐

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

  2. 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 ...

  3. 633.平方数之和(Sum of Square Numbers)

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

  4. LeetCode633 | Sum of Square Numbers (Easy)

    题目地址(633. 平方数之和) https://leetcode-cn.com/problems/sum-of-square-numbers/ 题目描述 给定一个非负整数 c ,你要判断是否存在两个 ...

  5. C#LeetCode刷题之#633-平方数之和( Sum of Square Numbers)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3885 访问. 给定一个非负整数 c ,你要判断是否存在两个整数 ...

  6. 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 ...

  7. [CF1598G]The Sum of Good Numbers

    The Sum of Good Number 题解 这种高精加法哈希比较的题真的很臭呀,赛后一群人在那里卡模数,真的吐了 我们考虑如何快速比较两个大整数的和,显然,哈希是一种很好的方法,所以我们可以将 ...

  8. Sum of Even Numbers After Queries

    Solution: 转载于:https://www.cnblogs.com/Julietma/p/10414394.html

  9. LeetCode | 我的LeetCode之旅(持续更新ing)

    我的LeetCode算法之旅,记录每天学习LeetCode的进程目录. 算法思想 1.双指针 LeetCode167 | 有序数组的 Two Sum 167.Two Sum II - Input ar ...

最新文章

  1. 忽悠神经网络指南:教你如何把深度学习模型骗得七荤八素
  2. 2016 大连网赛---Different GCD Subarray Query(GCD离散+树状数组)
  3. 还在网上找Demo?这个Java项目真香!
  4. Docker 的日志相关整理
  5. 华为徐直军:以持续创新加快数字化发展
  6. python解析html的库_python解析html开发库pyquery使用方法
  7. HTML项目代码编写规范
  8. 有谁做过在C# winform里,显示3D max文件的呢?请赐教了。
  9. Java动态规划走金字塔_【动态规划基础】数字金字塔
  10. java jframe 图标_java怎么修改jframe图标?
  11. 12张大数据图看看2016年世界各地发生大事件!
  12. 官宣!AutoSec第六届中国汽车网络安全周火热来袭,10大特色首度曝光!1000+精准专业观众、60+OEM竞相参与
  13. 找到一个电信代理服务器~
  14. 敏捷开发 敏捷个人_在敏捷2013中寻找答案
  15. encrypted勒索病毒攻击nas服务器,服务器中了勒索病毒解密数据恢复
  16. 对冲基金母基金(FoHF)
  17. 【Unity Shader】(2)半兰伯特模型 构建光照
  18. 黑群晖USB直连计算机,群辉(黑群辉)自动/定时备份U盘数据到硬盘内--原创
  19. 概念整理ia32/x86/amd64/ia64/arm64
  20. 要matlab标定数据做双目相机矫正OpenCV C++

热门文章

  1. 中缀转后缀表达式并求值
  2. 升级 Visual Studio 2015 CTP 5 的坑、坑、坑
  3. awk之特征相同行的合并 ~转
  4. 控件联动(三级联动)
  5. 利用vagrant快速搭建rails开发环境
  6. Jumony入门(二)初识选择器
  7. Python类继承简单实现
  8. 使用移动设备 连接到Exchange Server 2007
  9. PAT甲级1088 Rational Arithmetic:[C++题解]分数的加减乘除
  10. messenger支持查找附近的人功能吗_最新的 macOS Catalina 正式版,值得更新吗?