Skip to content
LC-0633 Medium LeetCode

633. Sum of Square Numbers

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 36% Topics: Math, Two Pointers, Binary Search
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(sqrt(c) * logc)
# Space: O(1)

import math


class Solution(object):
    def judgeSquareSum(self, c):
        """
        :type c: int
        :rtype: bool
        """
        for a in xrange(int(math.sqrt(c))+1):
            b = int(math.sqrt(c-a**2))
            if a**2 + b**2 == c:
                return True
        return False

Solution from kamyu104/LeetCode-Solutions · MIT