Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 1.18 KB

633-sum-of-square-numbers.md

File metadata and controls

54 lines (37 loc) · 1.18 KB

633. Sum of Square Numbers - 平方数之和

给定一个非负整数 c ,你要判断是否存在两个整数 ab,使得 a2 + b2 = c。

示例1:

输入: 5
输出: True
解释: 1 * 1 + 2 * 2 = 5

 

示例2:

输入: 3
输出: False

题目标签:Math

题目链接:LeetCode / LeetCode中国

题解

Language Runtime Memory
python3 212 ms N/A
class Solution:
    def judgeSquareSum(self, c):
        """
        :type c: int
        :rtype: bool
        """
        tmp = set()
        for i in range(int(c**0.5)+1):
            tmp.add(i*i)
        for ii in tmp:
            if c - ii in tmp:
                return True
        return False