LeetCode 题解之Find Peak Element
1、题目描述
2、题目分析
在数组的首尾各加入INT_MIN ,然后遍历数组。
3、代码
int findPeakElement(vector<int>& nums) {
if( nums.size() == )
return ; nums.insert( nums.begin(), INT_MIN );
nums.push_back( INT_MIN ); for( vector<int>::iterator it = nums.begin()+; it != nums.end() - ; ++it ){
if( *it > *(it + ) && *it > *(it-) )
return (it - nums.begin() - );
}
}
LeetCode 题解之Find Peak Element的更多相关文章
- 【LeetCode】162. Find Peak Element 解题报告(Python)
[LeetCode]162. Find Peak Element 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/ ...
- LeetCode OJ 162. Find Peak Element
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- 【LeetCode】162. Find Peak Element (3 solutions)
Find Peak Element A peak element is an element that is greater than its neighbors. Given an input ar ...
- LeetCode OJ:Find Peak Element(寻找峰值元素)
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- 【刷题-LeetCode】162 Find Peak Element
Find Peak Element A peak element is an element that is greater than its neighbors. Given an input ar ...
- leetcode 日记 162. Find Peak Element java python
根据题目可知,输入为:一个相邻元素不相等的数列,输出为:其中一个(上)峰值的序号.并且要求时间复杂度为logn 分析:由于题目要求时间复杂度为logn,因此不能进行全部遍历.又因为只需要找到其中的一个 ...
- LeetCode Find Peak Element
原题链接在这里:https://leetcode.com/problems/find-peak-element/ 题目: A peak element is an element that is gr ...
- (二分查找 拓展) leetcode 162. Find Peak Element && lintcode 75. Find Peak Element
A peak element is an element that is greater than its neighbors. Given an input array nums, where nu ...
- [LeetCode] Find Peak Element 求数组的局部峰值
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
随机推荐
- Spring Boot 项目发布到 Tomcat 服务器
第 1 步:将这个 Spring Boot 项目的打包方式设置为 war.<packaging>war</packaging> SpringBoot 默认有内嵌的 tomcat ...
- thinkphp 实现rabbitMq常驻进程消费队列
1,项目一级目录新建一个server文件 #!/usr/bin/env php <?php try { require __DIR__ . "/start.php"; } c ...
- 关于作用域范围Scope
举个例子,如下: public class C { public int a = 2; public void test(int b) { int c = 3; for (int d = 3; a & ...
- C/C++ -- Gui编程 -- Qt库的使用 -- 使用自定义类
1.新建空Qt工程 2.新建C++类HelloQt 3.新建ui文件,添加部件,重命名主窗体(对话框)类名HelloQt,构建生成ui头文件 4.修改头文件helloqt.h #ifndef HELL ...
- golang的并行快速排序
.nums[]作为core,将nums中大于core的元素放入greater,将不大于core的元素放入less 当nums长度为1时往ch中写入此元素 .分别对less和greater进行1操作(并 ...
- #!/usr/bin/python和#!/usr/bin/env 的区别
#!/usr/bin/python 通常在一个.py文件开头都会有这个语句 它只在Linux系统下生效,意思是当作为可执行文件运行时调用的解释器的位置上面代码的意思是调用/usr/bin/下的Pyth ...
- php发送post请求的三种方法
引用:http://blog.sjzycxx.cn/post/435/ 1.使用 file_get_contents() /** * 发送post请求 * @param string $url 请求地 ...
- [PY3]——Queue
Queue class Queue(builtins.object) __init__(self, maxsize=0) empty(self) full(self) get(self, block= ...
- dll(动态链接库)的编写
很可能有人会困惑dll究竟是什么,又改如何编写dll呢?今天,我就记录下编写以及调用动态链接库的步骤吧. 1.启动visuanl 6.0,新建工程 dll,如上图 2.在Source File中新建一 ...
- 如何使用 Telegram
Telegram是一款加密的实时通讯软件,本文告诉大家如何使用 这个软件. 在使用之前,需要保证自己已经开了梯子,如果没有梯子,那么就无法使用这个工具. 假如梯子是 127.0.0.1 端口 1080 ...