classSolution(object): defmySqrt(self, x): """ :type x: int :rtype: int """ left = 1 right = x / 2 if x < 2: return x while left <= right: mid = left + (right-left)/2 if x/mid > mid: left = mid + 1 elif x/mid < mid: right = mid - 1 else: return mid return (left+right)/2 defisPerfectSquare(self, num): """ :type num: int :rtype: bool """ z = self.mySqrt(num) return z * z == num