LeetCode: Find Sqrt(x)
Problem: https://leetcode.com/problems/sqrtx/description/ Code: class Solution: def mySqrt(self, x: int) -> int: if x <= 1: return x low, high = 1, x // 2 while low <= high: mid = (low + high) // 2...
Search for a command to run...
Articles tagged with #binary-search-algorithm
Problem: https://leetcode.com/problems/sqrtx/description/ Code: class Solution: def mySqrt(self, x: int) -> int: if x <= 1: return x low, high = 1, x // 2 while low <= high: mid = (low + high) // 2...
Problem: https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/ Code: class Solution: def minDays(self, bloomDay: List[int], m: int, k: int) -> int: # we need m bouquets # each bouquets should have k adjacent flo...
Problem: https://leetcode.com/problems/binary-search/description/ Code: class Solution: def search(self, nums: List[int], target: int) -> int: if not nums: return -1 low, high = 0, len(nums)-1 while low<=high...