Given an array of integers L, validate whether it is a mountain array or not. A mountain array satisfies the following rules:
- The size of the array n is equal or more than 3.
- There is a index k that L[0] < L[1] < L[2] ….<L[k], and L[k] > L[k+1] > L[k+2] > ….>L[n-1]
Sample Input:
[10, 20 , 30, 40, 50, 60, 70, 6, 5, 4, 3, 2, 1]
Sample Output:
True
数据结构和算法:初级练习题 #45 – 山形数组
给定一个数组 L,检查它是否是山形数组。一个山形数组符合下列条件:
- 数组 L 的长度 n 大于或等于3
- 数组 L 中存在一个峰值(其索引为k),峰值前面的数值从索引0开始:L[0] < L[1] < L[2] < … < L[k]。峰值后面的数值从索引 k 开始:L[k] > L[k+1] > L[k+2] > … > L[n-1]。
输入样例:
[10, 20 , 30, 40, 50, 60, 70, 6, 5, 4, 3, 2, 1]
输出样例:
True