633. Sum of Square Numbers
1. Description
Given a non-negative integer c, decide whether there’re two integers a and b such that $a^2$ + $b^2$ = c.
2. Example
Example 1
Input: c = 5
Output: true
Explanation: 1 * 1 + 2 * 2 = 5
Example 2
Input: c = 3
Output: false
3. Constraints
- 0 <= c <= 2$^{31}$ - 1
4. Solutions
Library
n = c
Time complexity: O($\sqrt{n}$)
Space complexity: O(1)
| |
Two Pointers
n = c
Time complexity: O($\sqrt{n}$)
Space complexity: O(1)
| |