Skip to content

Commit 453fda7

Browse files
authored
852. peak Index in a Mountain Array
1 parent b810371 commit 453fda7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

852. peak Index in a Mountain Array

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//__________________ Binary Search Question _______________________________
2+
3+
4+
class Solution {
5+
public:
6+
int peakIndexInMountainArray(vector<int>& arr) {
7+
int s = 0;
8+
int e = arr.size() - 1;
9+
// int mid = s+(e-s)/2;
10+
while(s<e){
11+
int mid = s+(e-s)/2;
12+
if(arr[mid] < arr[mid+1]){
13+
s = mid+1;
14+
}
15+
else{
16+
e = mid;
17+
}
18+
}
19+
return s;
20+
}
21+
};

0 commit comments

Comments
 (0)