Find Peak Element
来源:互联网 发布:网络流行词汇 编辑:程序博客网 时间:2024/05/21 21:43
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.
找到一个波峰元素。特殊情况是最后一个大于倒数第二个,也算波峰。
public int findPeakElement(int[] nums) {if(nums==null||nums.length<2)return 0;if(nums[nums.length-1]>nums[nums.length-2])return nums.length-1;for(int i=1;i<nums.length-1;i++){if(nums[i]>nums[i-1]&&nums[i]>nums[i+1])return i;}return 0;}
0 0
- [LeetCode] Find Peak Element
- Find Peak Element
- Leetcode:Find Peak Element
- Find Peak Element
- Find Peak Element
- Find Peak Element
- LeetCode Find Peak Element
- leetcode: Find Peak Element
- leetcode:Find Peak Element
- Find Peak Element
- Find Peak Element
- Find Peak Element
- LeetCode Find Peak Element
- Find Peak Element --leetcode
- Leetcode Find Peak Element
- [LeetCode] Find Peak Element
- Find Peak Element [Medium]
- Leetcode Find Peak Element
- 博弈论--两兄弟分钱
- copy
- struts2 中chain、redirect、redirectaction的区别
- HDU 5328 Problem Killer(简单DP)
- 大型web系统中缓存的使用
- Find Peak Element
- [iOS]字符串转字典
- 64-bit Itanium与x64
- block块页面传值
- 练钢琴想起的关于耐心信心和勇气
- hdu1316
- MVP和MVC模式解读与实战运用(一)
- Linux中环境变量文件及配置
- 关于tomcat的多域名配置