Talentd
FleetCode

367. Valid Perfect Square

Easy44.8% acceptance8 companies

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:

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.

Constraints:

  • 1 <= num <= 231 - 1
8:44
Still stuck?Read 4 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def isPerfectSquare(self, num: int) -> bool:
3
Starter codePython 3Spaces: 4
Examples
Input
16
Input
14
Your code is saved on this device.Solution