Valid Perfect Square

Given a positive integer num, return true if num is a perfect square or false otherwise.

A perfect square is an integer that is the square of an integer. In other words, it is the product of some integer with itself.

You must not use any built-in library function, such as sqrt.

Example 1
Inputnum = 16
Outputtrue
We return true because 4 * 4 = 16 and 4 is an integer.
Example 2
Inputnum = 14
Outputfalse
We return false because 3.742 * 3.742 = 14 and 3.742 is not an integer.

Constraints

  • 1 <= num <= 2^31 - 1

Asked at 7 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate