题解 | #【模板】栈#
二分查找
http://www.nowcoder.com/questionTerminal/28d5a9b7fc0b4a078c9a6d59830fb9b9
PYTHON
class BinarySearch: def erfen(self,ls,left,right,val): if left <= right: mid = (left + right) // 2 if val == ls[mid]: return mid elif val < ls[mid]: return self.erfen(ls, left, mid-1, val) else: return self.erfen(ls,mid+1,right,val) else: return -1 def getPos(self, A, n, val): # write code here mid = self.erfen(A,0,n-1, val) if mid >=0 : while A[mid-1] == val and mid >=1: mid -= 1 return mid return -1