# 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 that a2 + b2 = c.

Example 1:

Input: 5
Output: True
Explanation: 1 * 1 + 2 * 2 = 5

Example 2:

Input: 3
Output: False

# Solution

Approach 1: two pointers.

# Code (Python)

Approach 1:

class Solution:
    def judgeSquareSum(self, c: int) -> bool:
        # essentially a two sum problem with sorted nums
        l, r = 0, int(c ** (0.5))
        while l <= r:
            if l ** 2 + r ** 2 == c:
                return True
            elif l ** 2 + r ** 2 < c:
                l += 1
            else:
                r -= 1
        return False

# Code (C++)

Approach 1:

Approach 2: