Sum of Square Numbers

Problem Id: 633 Difficulty: Medium


Intuition

Solution


class Solution:
    def judgeSquareSum(self, c: int) -> bool:
        mapping = set()
        for i in range(c + 1):
            n = i * i
            if n > c:
                return False
            mapping.add(n)
            if c - n in mapping:
                return True