Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def findMin(nums):
- """
- :type nums: List[int]
- :rtype: int
- """
- N = len(nums)
- hi= N-1
- lo = 0
- if nums[lo]<nums[hi]:
- return nums[lo]
- while lo<=hi:
- mid = (lo+hi)//2
- next = (mid+1)%N
- prev = (mid+N-1)%N
- if nums[mid]<=nums[next] and nums[mid]<=nums[prev]:
- return nums[mid]
- elif nums[0]<nums[mid]:
- lo = mid + 1
- elif nums[N-1]>nums[mid]:
- hi = mid - 1
- print(findMin([11,13,15,17]))
- output : 11
- class Solution(object):
- def findMin(self, nums):
- """
- :type nums: List[int]
- :rtype: int
- """
- N = len(nums)
- hi= N-1
- lo = 0
- while lo<=hi:
- mid = (lo+hi)//2
- nxt = (mid+1)%N
- prev = (mid+N-1)%N
- if nums[mid]<=nums[nxt] and nums[mid]<=nums[prev]:
- return nums[mid]
- elif nums[0]<nums[mid]:
- lo = mid + 1
- elif nums[N-1]>nums[mid]:
- hi = mid - 1
- output : None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement