Description
Given a positive integer num, write a function that returns true if num is a perfect square, else false. You must not use any built-in library function such as sqrt.
Examples
Input:
num = 16Output:
trueExplanation:
4² = 16.
Input:
num = 14Output:
falseExplanation:
14 is not a perfect square. 3^2 = 9 and 4^2 = 16, so 14 falls between two perfect squares.
Input:
num = 1Output:
trueExplanation:
1² = 1, so 1 is a perfect square. This tests the edge case of the smallest possible input.
Constraints
- •
1 ≤ num ≤ 2³¹ - 1