左闭右开

public class Solution {
    public int search (int[] nums, int target) {
      // search [lo, hi)
      int lo = 0, hi = nums.length;
      
      while (lo < hi) {
        int mid = lo + ((hi-lo) >> 1);
        if (nums[mid] == target) {
          return mid;
        } else if (nums[mid] >= target) {
          hi = mid;  // search left
        } else {
          lo = mid + 1; // search right
        }
      }
      
      return -1; // not found
    }
}