Given a positive integer num, return true if num is a perfect square and false otherwise. A perfect square is an integer that equals some integer multiplied by itself, such as 16 = 4 * 4. You must not use any built-in square root function.
Given a positive integer num, return true if num is a perfect square and false otherwise. A perfect square is an integer that equals some integer multiplied by itself, such as 16 = 4 * 4. You must not use any built-in square root function.
Example 1:
Input: {"num":16}
Output: true
Constraints:
1≤num≤231−1
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"num":16}
Is 16 a perfect square? Its root, if it exists, is somewhere in [1, 16]. Binary search for a side length whose square is exactly 16.
Does a mid x mid square fill num exactly?
dashed = area 16
num
num = 16
mid = -
mid² = -
Candidate sides
all sides 1 .. 16window holds 16 candidateslo 1hi 16