class Solution:
def search(self, nums: List[int], target: int) -> int:
if not nums:
return -1
l, r = 0, len(nums) - 1
while l <= r:
mid = (l + r) // 2
if nums[mid] == target:
return mid
# 左半部分是有序
if nums[0] <= nums[mid]:
# target落在左半部分有序区域内
if nums[0] <= target < nums[mid]:
r = mid - 1
else:
l = mid + 1
else: # 右半部分是有序
# target落在右半部分有序区域内
if nums[mid] < target <= nums[len(nums) - 1]:
l = mid + 1
else:
r = mid - 1
return -1