Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def f(self, nums, mid, left, right):
- # first element which satisfied the below condition
- # is the minimum element of the array
- if (nums[mid] < nums[right]):
- return True
- else:
- return False
- def findMin(self, nums: List[int]) -> int:
- left = 0
- right = len(nums) - 1
- # template for finding first inflection point or pivot point.
- # This is useful for finding first element which satisfies a condition
- while(left < right):
- mid = left + (right - left)//2
- if self.f(nums, mid, left, right):
- right = mid
- else:
- left = mid + 1
- # base case when array is not rotated
- return nums[left]
Advertisement
Add Comment
Please, Sign In to add comment