HTMLify

LeetCode - Longest Strictly Increasing or Strictly Decreasing Subarray - Go
Views: 26 | Author: abh
func longestMonotonicSubarray(nums []int) int {
    l := 0

    le := 0
    ci := 0
    for _, v := range nums {
        if v > le {
            ci++
        } else {
            ci = 1
        }
        le = v
        if ci > l {
            l = ci
        }
    }

    le = 51
    cd := 0
    for _, v := range nums {
        if v < le {
            cd++
        } else {
            cd = 1
        }
        le = v
        if cd > l {
            l = cd
        }
    }
    
    return l
}

Comments