lc704.二分查找
【递归】
class Solution: def search(self, nums: List[int], target: int) -> int: if len(nums) == 0: return -1 mid = int(len(nums)-1 / 2) result = 0 if nums[mid] > target: result = self.search(nums[:mid], target) elif nums[mid] < target: result = self.search(nums[mid+1:], target) elif nums[mid] == target: return mid return result
浙公网安备 33010602011771号