Problem :

https://leetcode.com/problems/search-in-rotated-sorted-array/


My Solution :

class Solution:
def search(self, nums, target):
if nums:
left, right = 0, len(nums)-1
while left < right:
mid = (left + right) // 2
if target < nums[mid]:
if nums[mid] <= nums[right] or nums[right] < target:
right = mid - 1
else:
left = mid + 1
elif nums[mid] < target:
if nums[left] <= nums[mid] or target < nums[left]:
left = mid + 1
else:
right = mid - 1
else:
return mid
if nums[left] == target:
return left
return -1