We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一个整数数组 A,如果它是有效的山脉数组就返回 true,否则返回 false。
让我们回顾一下,如果 A 满足下述条件,那么它是一个山脉数组:
输入:[2,1] 输出:false
输入:[3,5,5] 输出:false
输入:[0,3,2,1] 输出:true
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/valid-mountain-array 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered:
很简单,找到最大值,然后从头到最大值的过程应该是递增的,从最大值到尾的过程应该是递减的。
func validMountainArray(A []int) bool { index, maxValue := 0, 0 for i, v := range A { if v > maxValue { maxValue = v index = i } } if index == 0 || index == len(A)-1 { return false } for i := 0; i+1 <= index; i++ { if A[i] >= A[i+1] { return false } } for i := index; i+1 < len(A); i++ { if A[i] <= A[i+1] { return false } } return true }
Sorry, something went wrong.
No branches or pull requests
给定一个整数数组 A,如果它是有效的山脉数组就返回 true,否则返回 false。
让我们回顾一下,如果 A 满足下述条件,那么它是一个山脉数组:
示例 1:
示例 2:
示例 3:
提示:
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/valid-mountain-array
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered: