标签:
二分查找算法:
二分查找求下界:
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; } };
二分查找求上界:
标签:
原文地址:http://www.cnblogs.com/gaoyanqing/p/4824284.html