leetcode--81-搜索旋转排序数组②
2020-12-13 06:27
标签:ima 排序 targe search return lis bool 旋转 alt 题目描述: 33题 方法一: leetcode--81-搜索旋转排序数组② 标签:ima 排序 targe search return lis bool 旋转 alt 原文地址:https://www.cnblogs.com/oldby/p/11180038.htmlclass Solution:
def search(self, nums: List[int], target: int) -> bool:
l, r = 0, len(nums) - 1
while l r:
m = (l+r) // 2
if target == nums[m]:
return True
if nums[m]==nums[l]==nums[r]:
l += 1
r -= 1
elif nums[m] >= nums[l]:
if nums[l] nums[m]:
r = m - 1
else:
l = m + 1
else:
if nums[m] nums[r]:
l = m + 1
else:
r = m - 1
return False