首页 > 其他 > 详细

Lintcode 75.寻找峰值

时间:2017-01-01 23:35:53      阅读:231      评论:0      收藏:0      [点我收藏+]

技术分享

---------------------------------------

 

按照给定的峰值定义,峰值的左半部分一定是递增的,所以只要找到不递增的即可。

 

AC代码:

class Solution {
    /**
     * @param A: An integers array.
     * @return: return any of peek positions.
     */
    public int findPeak(int[] A) {
        for(int i=1;i<A.length;i++){
            if(A[i]>=A[i+1]) return i;
        }
        return -1;
    }
}

 

 

题目来源: http://www.lintcode.com/zh-cn/problem/find-peak-element/#

 

Lintcode 75.寻找峰值

原文:http://www.cnblogs.com/cc11001100/p/6241683.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!