LintCode_75_寻找峰值
来源:互联网 发布:淘宝助理线上回收站 编辑:程序博客网 时间:2024/05/17 08:17
你给出一个整数数组(size为n),其具有以下特点:
- 相邻位置的数字是不同的
- A[0] < A[1] 并且 A[n - 2] > A[n - 1]
假定P是峰值的位置则满足A[P] > A[P-1]
且A[P] > A[P+1]
,返回数组中任意一个峰值的位置。
注意事项
数组可能包含多个峰值,只需找到其中的任何一个即可
样例
给出数组[1, 2, 1, 3, 4, 5, 7, 6]
返回1
, 即数值 2 所在位置, 或者6
, 即数值 7 所在位置.
究竟为什么这题是中等难度
class Solution { /** * @param A: An integers array. * @return: return any of peek positions. */ public int findPeak(int[] A) { // write your code here for(int i = 1 ; i < A.length -1 ; i++){ if(A[i] > A[i+1] && A[i] > A[i-1]){ return i; } } return -1; }}
0 0
- LintCode_75_寻找峰值
- 寻找峰值
- 寻找峰值
- 寻找峰值
- 寻找峰值
- 寻找峰值
- 寻找峰值
- Matlab------------寻找峰值函数
- Matlab---寻找峰值函数
- findpeaks 寻找峰值函数
- LintCode-寻找峰值
- 题目:寻找峰值
- [LintCode]寻找峰值
- 【Matlab】寻找峰值函数
- lintcode:寻找峰值
- LintCode 75 寻找峰值
- findpeaks 寻找峰值函数
- LintCode : 寻找峰值
- 通过win7中cmd命令提示符telnet模拟http请求
- 如何才能不崩溃1: KVO and Manual Bindings
- Swift NavigationController的使用
- php的config.inc.php
- 三角形
- LintCode_75_寻找峰值
- java.lang.UnsatisfiedLinkError
- OSError: libiomp5.so: cannot open shared object file: No such file or directory
- sap sybase16备份及还原测试
- Python学习笔记-argparse
- 链表归并排序
- 关于GPL协议的理解(开源与商用、免费与收费的理解)
- 如何建立sitemap网站地图(google)
- HDU 1047(大数相加)(数组模拟)