Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def findMin(self, a: List[int]) -> int:
- l,r=0,len(a)-1
- while l<r:
- m=(l+r)>>1
- if a[m]>a[r]:#Always compare with right side that too decreasing order
- l=m+1
- elif a[m]==a[r]:
- r=r-1
- else:
- r=m
- return a[l]
- class Solution:
- def findMin(self, a: List[int]) -> int:
- ans=inf
- def bin_dfs(s,e):
- nonlocal ans
- if e-s<=1:#If array is length of 2 or less than 2
- ans=min(ans,a[s],a[e])
- return
- else:
- m=s+(e-s)//2
- if a[s]<=a[m]:#If left part is sorted go for right
- bin_dfs(m,e)
- if a[m]<=a[e]:#If right part is sorted go for left
- bin_dfs(s,m)
- bin_dfs(0,len(a)-1)
- return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement