Skip to content

Commit a44b806

Browse files
authored
162. Find Peak Element
same as 852. peak element in a mountain array
1 parent 08f6489 commit a44b806

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

162. Find Peak Element

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//.........................Binary Search.......................................//
2+
//same as Leetcode 852. find peak Element
3+
int findPeakElement(vector<int>& nums) {
4+
// This question is same as leetCode 852.peak index in a mountain array
5+
int left =0;
6+
int right = nums.size() - 1;
7+
while(left < right){
8+
int mid = left+(right-left)/2;
9+
if(nums[mid] < nums[mid+1]){
10+
left = mid+1;
11+
}
12+
else{
13+
right = mid;
14+
}
15+
}
16+
return left;
17+
}

0 commit comments

Comments
 (0)