LeetCode 筆記 - 69. Sqrt(x) Posted on 2022-07-03題目在此 69. Sqrt(x)給定一個數字,請給出平方根的整數部分解題思維這題就是典型的 Binary Search 的應用題程式碼1234567891011121314151617class Solution: def mySqrt(self, x: int) -> int: start = 0 end = x while start <= end: mid = (start + end) // 2 check_num = mid ** 2 if check_num <= x < (mid + 1) ** 2: return mid elif x < check_num: end = mid - 1 else: start = mid + 1也許你也會想看看LeetCode 筆記 - 78. SubsetsLeetCode 筆記 - 647. Palindromic SubstringsLeetCode 筆記 - 97. Interleaving String