633. Sum of Square Numbers
LeetCode 633. Sum of Square Numbers
Description
Given a non-negative integer c
, decide whether there're two integers a
and b
such that a^2 + b^2 = c
.
Example 1:
Example 2:
Example 3:
Constraints:
0 <= c <= 2^31 - 1
Tags
Math, Two Pointers
Solution
With two pointers a
and b
, starting from 0 and square root of c
respectively, we can keep checking for the existence of a^2 + b^2 == c
before they encounter.
Complexity
Time complexity:
Space complexity:
Code
Reference
Last updated
Was this helpful?