MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / binarySearchLeft

Method binarySearchLeft

java/1095-find-in-mountain-array.java:35–50  ·  view source on GitHub ↗
(MountainArray array, int target, int right)

Source from the content-addressed store, hash-verified

33 }
34
35 public int binarySearchLeft(MountainArray array, int target, int right) {
36 int left = 0;
37
38 while (left<=right) {
39 int mid = left + (right - left)/2;
40 int midValue = array.get(mid);
41 if (midValue < target) {
42 left = mid + 1;
43 } else if (midValue > target) {
44 right = mid - 1;
45 } else {
46 return mid;
47 }
48 }
49 return -1;
50 }
51
52 public int binarySearchRight(MountainArray array, int target, int left) {
53 int right = array.length() - 1;

Callers 1

findInMountainArrayMethod · 0.95

Calls 1

getMethod · 0.45

Tested by

no test coverage detected