Valid Perfect Square
Given a positive integer num
, write a function which returns True
if num is a perfect square else False
.
Do not
use any built-in library function such as sqrt.Have you met this question in a real interview? YesProblem Correction
Example
For example:
Given num = 16
Returns True
套用二分法模板,注意overflow,要cast成long,时间复杂度O(logN)
Last updated