Hexo


  • 首頁

  • 分類

  • 關於

  • 歸檔

  • 標籤

lc162-Find Peak Element

發表於 2016-12-13   |   分類於 leetcode   |   0 comments   |  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
int findPeakElement(vector<int>& nums) {
int h = nums.size()-1;
int l = 0;
while(l<h-1) {
int mid = (h+l)/2;
if (nums[mid-1] < nums[mid]) {
if (nums[mid] > nums[mid+1]) return mid;
l = mid+1;
}
else h = mid-1;
}
return (nums[l]>nums[h])?l:h;
}
};
#lc-medium #binary search
lc98-Validate Binary Search Tree
lc50-Pow(x, n)
  • 文章目錄
  • 本站概覽
Jane Doe

Jane Doe

93 文章
4 分類
41 標籤

此文章未包含目錄

©   2017 Jane Doe 本站訪客數 人 本站總訪問量 次