Medium 162题 Find Peak Element
来源:互联网 发布:万方数据库账号密码 编辑:程序博客网 时间:2024/05/23 20:16
Question:
A peak element is an element that is greater than its neighbors.
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[n] = -∞
.
For example, in array [1, 2, 3, 1]
, 3 is a peak element and your function should return the index number 2.
Solution:
public class Solution { public int findPeakElement(int[] nums) { int len=nums.length; int ans=0; for(int i=0;i<=len-2;i++) { if(nums[i]>=nums[i+1]) { ans=i; break; } if(i==len-2&&nums[i]<=nums[i+1]) ans=i+1; } return ans; }}
0 0
- Medium 162题 Find Peak Element
- Find Peak Element [Medium]
- [Leetcode 162, Medium] Find Peak Element
- 【LeetCode】(162)Find Peak Element(Medium)
- Leetcode 162. Find Peak Element (Medium) (cpp)
- 162Find Peak Element
- [162]Find Peak Element
- 162Find Peak Element
- LeetCode(162) Find Peak Element
- [leetcode 162] Find Peak Element
- leetcode-162 Find Peak Element
- [LeetCode 162]Find Peak Element
- LeetCode 162 Find Peak Element
- [leetcode] #162 Find Peak Element
- Find Peak Element - LeetCode 162
- Leetcode[162]-Find Peak Element
- leetcode-162-Find Peak Element
- !leetcode[162]:Find Peak Element
- HTML+CSS基础 a active设置所有,点击超链接文本时下划线消失
- 双向链表实现约瑟夫环
- android 不初始化...一个的问题,getLoaderManager ().initLoader LoaderManager
- Linux 信号,僵尸进程,(面试)
- Ubuntu12.04 远程桌面连接说明
- Medium 162题 Find Peak Element
- HTML+CSS基础 a hover设置所有,鼠标移动到超链接文本处超链接变小
- Activity和service的两种绑定方法
- js中实现封装
- servlet3.1规范: 第10章 Web应用
- Linux网卡驱动程序详解
- [MSSQL]SQL Server 2008 收缩日志 清空删除大日志文件
- HTML+CSS基础 border-bottom在指定p标签的文本下方添加双细实线
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-浏览器对象模型