Skip to content

Commit f453927

Browse files
committed
 Find Peak Element
1 parent 8abe5f0 commit f453927

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

162.cpp

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

0 commit comments

Comments
 (0)