Skip to content

Commit e54835e

Browse files
committed
Add Q162
1 parent 6894962 commit e54835e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int findPeakElement(vector<int>& nums) {
4+
int len = nums.size();
5+
if (len < 2) return len-1;
6+
int low = 0, high = len-1;
7+
while (low < high) {
8+
int mid1 = (low+high)/2;
9+
int mid2 = mid1 + 1;
10+
if (nums[mid1] > nums[mid2]) {
11+
high = mid1;
12+
} else {
13+
low = mid2;
14+
}
15+
}
16+
return low;
17+
}
18+
};

0 commit comments

Comments
 (0)