Skip to content

Commit 0d6fdf0

Browse files
committed
162. Find Peak Element
1 parent 78cf61d commit 0d6fdf0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

find-peak-element.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//Runtime: 6 ms
2+
class Solution {
3+
public:
4+
int binary(vector<int>&A, int lo, int hi)
5+
{
6+
if (lo == hi)
7+
return lo;
8+
9+
int mid = lo + (hi - lo) / 2;
10+
if (A[mid] > A[mid + 1])
11+
return binary(A, lo, mid);
12+
13+
return binary(A, mid + 1, hi);
14+
}
15+
16+
int findPeakElement(vector<int>& nums) {
17+
return binary(nums, 0, nums.size() - 1);
18+
}
19+
};

0 commit comments

Comments
 (0)