leetcode.162. Find Peak Element
2016-05-16 19:53
495 查看
A peak element is an element that is greater than its neighbors.
Given an input array where
The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.
You may imagine that
For example, in array
Given an input array where
num[i] ≠ num[i+1], find a peak element and return its index.
The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.
You may imagine that
num[-1] = num = -∞.
For example, in array
[1, 2, 3, 1], 3 is a peak element and your function should return the index number 2.
class Solution { public: int findPeakElement(vector<int>& nums) { int low = 0; int high = nums.size()-1; while(low < high) { int mid = low + (high-low)/2; if(nums[mid] > nums[mid+1]) high = mid; else low = mid+1; } return low; } };
相关文章推荐
- vimtutor中文版
- Struts上传文件fileupload
- 推荐系统基础之一-简介
- JavaCAS操作
- [dp+数论]bzoj1004
- 学习心得 六 修改
- 数据库索引
- Sublime Text 3 绝对神器
- Android中EditText中的InputType
- hdoj 2055 An easy problem (单个字符)
- CSS 3 伪元素选择器
- iOS中直接使用Gif图片
- php中redis的安装
- 团体程序设计天梯赛-L3-004. 肿瘤诊断
- linux下常用文本编辑器的控制台启动命令
- [NOI2016模拟5.14]最长公共子序列
- CSS 3 伪类选择器
- 解决对话框报错方案
- chrome的广告过滤插件下载地址
- php使用ffmpeg向视频中添加文字字幕