Skip to content

Latest commit

 

History

History

valid-perfect-square

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Valid Perfect Square

LeetCode #: 367

Difficulty: Easy

Topics: Math, Binary Search.

Explanation

Given a positive integer num, write a function which returns True if num is a perfect square else False.

Note: Do not use any built-in library function such as sqrt.

Example 1:

Input: 16
Output: true

Example 2:

Input: 14
Output: false

Solution Explanation

This solution uses the Newton's Method to quickly find the square root of the number.

Reference: LeetCode Discuss Forum

Complexity Analysis

Time complexity: O(log n)

Space complexity: O(1)