Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. static int binarySearch(int x, int[] arr) {
  2. int left = 0;
  3. int right = arr.length;
  4. while (left < right) {
  5. int mid = (left + right) / 2;
  6. if (arr[mid] == x) {
  7. return arr[mid];
  8. } else if (x < arr[mid]) {
  9. right = mid;
  10. } else {
  11. left = mid + 1;
  12. }
  13. }
  14. return Integer.MIN_VALUE;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement