Open tsungtingdu opened 3 years ago
暴力解
var validMountainArray = function(arr) {
if (arr.length < 3) return false
let viewer = 0
let maxIdx = arr.indexOf(Math.max(...arr))
if (maxIdx === arr.length - 1 || maxIdx === 0) return false
while (viewer !== arr.length - 1) {
if (viewer < maxIdx && arr[viewer] >= arr[viewer + 1]) return false
if (viewer >= maxIdx && arr[viewer] <= arr[viewer + 1]) return false
viewer++
}
return true
};