class Solution: # @param A a list of integers # @param target an integer # @return a boolean def search(self, A, target): n=len(A) if n==0: return False left=0 right=n-1 while left<=right: mid=(left+right)//2 if left==right: return True if target==A[left] else False elif target==A[mid]: return True elif A[left]==A[mid]: left+=1 elif A[left]<A[mid]: if A[left]<=target<A[mid]: right=mid-1 else: left=mid+1 else: if A[mid]<target<=A[right]: left=mid+1 else: right=mid-1 return False
Tuesday, September 9, 2014
Leetcode: Search in Rotated Sorted Array II @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment