Skip to content

Latest commit

 

History

History
45 lines (34 loc) · 832 Bytes

0633._Sum_of_Square_Numbers.md

File metadata and controls

45 lines (34 loc) · 832 Bytes

633. Sum of Square Numbers

难度: Easy

刷题内容

原题连接

内容描述

Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.

Example 1:
Input: 5
Output: True
Explanation: 1 * 1 + 2 * 2 = 5
Example 2:
Input: 3
Output: False

解题方案

思路 1 - 时间复杂度: O(lgN)- 空间复杂度: O(1)******

from math import sqrt
class Solution(object):
    def judgeSquareSum(self, c):
        """
        :type c: int
        :rtype: bool
        """
        a = 0
        while a * a <= c:
            if int(sqrt(c - a * a)) == sqrt(c - a * a):
                return True
            a += 1
        return False