Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #use this only
- class Solution:
- def findMin(self, a: List[int]) -> int:
- n=len(a)
- if len(a)==1:return a[0]
- l,r=0,len(a)-1
- if a[0]<a[-1]:return a[0]
- while l<=r:
- m=(l+r)>>1
- if m-1>=0 and a[m-1]>a[m]:return a[m]
- if a[m]>a[m+1]:return a[m+1]
- if a[0]<a[m]:
- l=m+1
- else:
- r=m-1
- ------------------------------------------------------------------------------------------------------------------------
- #Always compare with right one
- #Better one
- class Solution:
- def findMin(self, a: List[int]) -> int:
- n=len(a)
- l,r=0,n-1
- while l<r:
- m=(l+r)>>1
- if a[m]>a[-1]:
- l=m+1
- else:
- r=m
- return a[l]
Advertisement
Add Comment
Please, Sign In to add comment