--- tags: data_structure_python --- # Valid perfect square https://leetcode.com/problems/valid-perfect-square/ ```python= class Solution: def isPerfectSquare(self, num: int) -> bool: perfect_square = int(num ** (1/2)) return perfect_square * perfect_square == num ``` ```python= class Solution: def isPerfectSquare(self, num: int) -> bool: left, right = 0, num while left <= right: mid = (left + right) // 2 square = mid * mid if square == num: return True if square > num: right = mid - 1 elif square < num: left = mid + 1 return False ```