Find Peak Element LeetCode solution in Java

1
class Solution {
2
public int findPeakElement(int[] nums) {
3
int start = 0;
4
int end = nums.length - 1;
5

6
while (start < end) {
7
int mid = start + (end - start) / 2;
8
if (nums[mid] > nums[mid + 1]) {
9
// It means that we are in decreasing part of the array
10
end = mid;
11
} else {
12
// It means that we are in increasing part of the array
13
start = mid + 1;
14
}
15
}
16
return start;
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0