二分法
class Solution(object):
def isPerfectSquare(self, num):
"""
:type num: int
:rtype: bool
"""
left,right=0,num
while left<=right:
mid=left+(right-left)/2
t=mid*mid
if t==num: return True
elif (t<num): left=mid+1
else: right=mid-1
return False
网友评论