peak num
class Solution {
public:
int findPeakElement(vector<int>& nums) {
int i=0;
int n=nums.size();
while(i<n){
if(i==0){ //处理第一位
if(nums[1] < nums[0])
return 0;
else {
i++;
continue;
}
}
if(i==n-1){ //处理最后一位
if(nums[i-1] < nums[i])
return i;
else{
i++;
continue;
}
}
if((nums[i-1]<nums[i])&&(nums[i]>nums[i+1]))
return i;
i++;
}
return 0; //处理只有一个元素的情况。。。注意。。。
}
};
peak num的更多相关文章
- LeetCode 162 Find Peak Element
Problem: A peak element is an element that is greater than its neighbors. Given an input array where ...
- Find Peak Element
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- 【leetcode】Find Peak Element
Find Peak Element A peak element is an element that is greater than its neighbors. Given an input ar ...
- find the peak value
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- Java for LeetCode 162 Find Peak Element
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- LeetCode Find Peak Element
原题链接在这里:https://leetcode.com/problems/find-peak-element/ 题目: A peak element is an element that is gr ...
- 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 --------- java
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- 【leetcode】Find Peak Element ☆
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
随机推荐
- Ionic学习笔记四 一些问题处理
版权声明:本文为博主原创文章,转载请留链接,非常感谢. 目录(?)[+] IONIC actionsheet 的cancel menu在android下不显示的bug 在 _action-sh ...
- php中对2个数组相加的函数
<?php function array_add($a,$b){ //根据键名获取两个数组的交集 $arr=array_intersect_key($a, $b); //遍历第二个数组,如果键名 ...
- form表单中控件较多,加载完成后切换页面都很慢的解决方法
form表单中控件较多,加载完成后点击都很慢,为什么?我一页面中form表单里面上百个控件(如input.select.radio.checkbox等),还有一些js脚本,加载速度还可以,都能全部显示 ...
- centos 下 django 1.8 配置好后 admin 后台无法显示 样式解决办法
解决前 解决命令 [root@ayibang-server static]# cat /etc/nginx/conf.d/office_djaong_uvpv.conf server { listen ...
- OC类方法和实例方法中的self区别
OC类方法和实例方法中的self Objective-C里面既有实例方法也类方法.类方法(Class Method) 有时被称为工厂方法(Factory Method)或者方便方法(Convenien ...
- javascript设计模式学习之四——单例模式,缓存与对象池
单例模式的定义:确保一个实例,并提供全局访问. 惰性单例的定义:只在需要的时候才创建对象. 在开发中,有些对象往往只需要一个,比如线程池.全局缓存.浏览器中的window对象等. java中的单例 关 ...
- struts 2.0部署
环境:linux centos 64位. 1)下载JDK6.0,具体文件名是:jdk-6u45-linux-x64.bin 安装:chmod 755 jdk*.bin ./jdk....bin 设置环 ...
- unresolved external symbol __report_rangecheckfailure 解决思路
__report_rangecheckfailure 是用来检查堆栈缓存溢出的,如果编译的时候打开GS(project property-->Configuration properties- ...
- Swift实战-小QQ(第1章):QQ登录界面
1.新建小QQ项目 2.将所需用到的图片资源(resource)文件夹,添加到项目中.并新建一个登录页面:LoginViewController.swift 3.修改LoginViewControll ...
- ShareSDKForANE 打包笔记
最近做了一个ShareSDK IOS的接入 (ANE) , 现在想想其实很简单 不过由于对Xcode,ANE的不熟悉也折腾了好久, 舔着脸打扰客服好几天… 呵呵 目前把我接入的一些步骤列出来 希望能帮 ...