JAVA实现lowerBound和upperBound函数
JAVA实现lowerBound和upperBound函数
//找到第一个大于等于x的位置 public static int lowerBound(User[] user , int low, int high, int x){ int mid; while (low <= high){ mid = (low + high)>>1; if(user[mid].likeValue >= x) high = mid-1; else low = mid+1; } return low; } //找到第一个大于x的位置 public static int upperBound(User[] user, int low, int high, int x){ int mid; while (low<high){ mid = (low+high)>>1; if(user[mid].likeValue<=x) low = mid+1; else high = mid; } return low; }