Skip to content

Commit 5ed5ca7

Browse files
authored
Added Solution for LeetCode Problem No. 162
1 parent fa84e4c commit 5ed5ca7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int findPeakElement(int[] arr) {
3+
int start = 0;
4+
int end = arr.length - 1;
5+
while (start < end) {
6+
// find the middle element
7+
int mid = start + (end - start) / 2;
8+
if (arr[mid] > arr[mid + 1]) {
9+
end = mid;
10+
} else if (arr[mid] < arr[mid + 1]) {
11+
start = mid + 1;
12+
}
13+
}
14+
return start;
15+
}
16+
}

0 commit comments

Comments
 (0)