二分查找算法:算法
二分查找求下界:spa
class BinarySearch { public: int getPos(vector<int> A, int n, int val) { // write code here int start=0, end=n; while(start < end){ int mid = (start + end)/2; if(A[mid] < val) start = mid +1; else end = mid ; } if(end == n || A[end] != val) return -1; else return end; } };
二分查找求上界:code