Leetcode Note: Go - Valid Mountain Array
Valid Mountain Array - LeetCode
https://leetcode.com/problems/valid-mountain-array/
- Go 言語で取り組んだメモ
回答
Valid Mountain Array - LeetCode
https://leetcode.com/problems/valid-mountain-array/solution/
[Go] Simple One Pass - LeetCode Discuss
https://leetcode.com/problems/valid-mountain-array/discuss/572172/Go-Simple-One-Pass
func validMountainArray(A []int) bool {
n, i := len(A), 0
if n < 3{
return false
}
for i+1<n && A[i] < A[i+1]{
i++
}
if i == 0 || i == n - 1{
return false
}
for i+1<n && A[i] > A[i+1]{
i++
}
return i == n -1
}