#367
Valid Perfect Square
pupil · 470 · lc easy +26 · verified · 44.7% accepted · 4,651 likes · top 27%
Description
A positive integer num is a perfect square when it equals some integer multiplied by itself. Return true if num is a perfect square and false otherwise.
Do not use any built-in square-root function such as sqrt.
Example 1:
Input: num = 16
Output: true
Explanation: We return true because 4 * 4 = 16 and 4 is an integer.
Example 2:
Input: num = 14
Output: false
Explanation: We return false because 3.742 * 3.742 = 14 and 3.742 is not an integer.
Code
1
2
3