perfect_square

  • 2022-12-14
  • 浏览 (643)

perfect_square.py 源码

# 有效的完全平方数

class Solution:
    def isPerfectSquare(self, num: int) -> bool:
        low, high = 1, num
        while low <= high:
            mid = (low + high) // 2
            if mid * mid < num:
                low = mid + 1
            elif mid * mid > num:
                high = mid - 1
            else:
                return True
        return False

你可能感兴趣的文章

find_peak_element

first_last_sort_array

search_rotated_sorted_array

0  赞