LeetCode: 852. Peak Index in a Mountain Array


Let’s call an array A a mountain if the following properties hold:
A.length >= 3
There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1]
Given an array that is definitely a mountain, return any i such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1].


Input: [0,1,0]
Output: 1
Input: [0,2,1,0]
Output: 1



func peakIndexInMountainArray(A []int) int {
    var index int
    for i := 1; i < len(A)-1; i++{
        if A[i-1] < A[i] && A[i] > A[i+1] {
            index = i
    return index
Next PostRead more articles

This Post Has 6 Comments

  1. Justin

    Long time supporter, and thought I’d drop a comment.

    Your wordpress site is very sleek – hope you don’t mind me asking what theme you’re using?
    (and don’t mind if I steal it? :P)

    I just launched my site –also built in wordpress like yours– but the theme slows (!) the
    site down quite a bit.

    In case you have a minute, you can find it by searching
    for “royal cbd” on Google (would appreciate any
    feedback) – it’s still in the works.

    Keep up the good work– and hope you all take care of yourself during the coronavirus scare!

    1. jirongwu81@gmail.com

      Just used OceanWP, I did not modify anything.
      Maybe you should use some plugin to boost webpage loading,like Fast Velocity Minify, WP Super Cache and so on.
      This website build in SiteGround, it has the SG Optimizer plugin.

      Thanks for your visting.

  2. RogerCeawl


    1. jirongwu81@gmail.com


  3. xbetldevvz

    very interesting but nothing is clear
    sГјperbetting Еџikayet var [url=https://sport.azavbioham.ml/1x_bet.html]1xBet[/url] betnow location

    1. jirongwu81@gmail.com

      Thanks a lot, I would change this problem in the future。