Advertisement
Guest User

Untitled

a guest
Aug 14th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. public int search(int[] nums, int target) {
  2. int low = 0;
  3. int high = nums.length - 1;
  4.  
  5. while (low <= high) {
  6. int mid = (low + high) >>> 1;
  7.  
  8. if (nums[mid] < target) {
  9. low = mid + 1;
  10. } else if (nums[mid] > target) {
  11. high = mid - 1;
  12. } else {
  13. return mid;
  14. }
  15. }
  16.  
  17. return -1;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement