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 = 16
Output:true
Explanation:

4² = 16.

Input:num = 14
Output:false
Explanation:

14 is not a perfect square. 3^2 = 9 and 4^2 = 16, so 14 falls between two perfect squares.

Input:num = 1
Output:true
Explanation:

1² = 1, so 1 is a perfect square. This tests the edge case of the smallest possible input.

Constraints

  • 1 ≤ num ≤ 2³¹ - 1

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!