class Solution: # @param A, a list of integers # @param target, an integer to be inserted # @return integer def searchInsert(self, A, target): left=0 right=len(A)-1 while left<=right: middle=int((left+right)/2) if target<A[middle]: right=middle-1 elif target==A[middle]: return middle else: left=middle+1 return middle if target<A[middle] else middle+1
Sunday, September 7, 2014
Leetcode: Search Insert Position @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment