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] ≠ ...
随机推荐
- Android ExpandableListView的下拉刷新实现
该控件的修改时根据PullToRefreshList的机制修改 下面是对ExpandableListView的扩展 package com.up91.gwy.view.componet; import ...
- 分享一下怎么开发一款图片视频类App,秒拍和prisma
第一步,分解短视频App的功能 我们在秒拍官网看到如此描述: [视频拍摄及导入]支持直接拍摄及导入手机本地的视频 [照片电影]照片专属特效,轻松创作照片电影 [MV特效]10余款全新MV特效,让普通视 ...
- java中 set,list,array(集合与数组)相互转换
public static Object[] List2Array(List<Object> oList) { Object[] oArray = oList.toArray(new ...
- SQL Server中的SQL语句优化与效率问题
很多人不知道SQL语句在SQL SERVER中是如何执行的,他们担心自己所写的SQL语句会被SQL SERVER误解.比如: select * from table1 where name='zhan ...
- 发布自己的nuget包;报错source parameter was not specified
16-10-27 VS下使用 程序包管理器控制台 运行: 1.cd 命令走到 工程文件夹下,使用 ls 命令查看当前目录: 2. 使用 nuget spec 创建: 3. 使用 nuget pack ...
- Virtual Box 增加虚拟硬盘容量
情景: 我现在用 Win10, 因为项目原因要在虚拟机装一个 Win7. 预先估计不足. Win7 C盘容量不够. 方法1: 增加虚拟硬盘文件. 首先把虚拟机 Win7 删掉 (但不要删虚拟硬盘文件, ...
- Linux 动态链接库学习笔记
参考资料: http://www.linuxidc.com/Linux/2012-01/50739.htm http://www.yolinux.com/TUTORIALS/LibraryArchiv ...
- 【Linux】 JDK安装及配置 (tar.gz版)
安装环境 Linux(Ubuntu 版) JDK安装 tar.gz为解压后就可以使用的版本,这里我将使用jdk-8u65-linux-x64.tar.gz版,安装到/usr/java/下 步骤一 将文 ...
- JAX-WS(二)之使用wsimport创建WebService客户端
客户端开发的通常过程是从已有的WSDL处罚,创建辅助类JAXB对象和Service代理类,然后基于这些类开发自己的客户端应用. 开发步骤: 创建eclipse项目: 运行wsimport命令生成客户端 ...
- SQL 数据库基础
SQL:Structured Quety Language SQL SERVER是一个以客户/服务器(c/s)模式访问.使用Transact-SQL语言的关系型数据库管理子系统(RDBMS) DBMS ...