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
如果数组是单调递增或单调递减的,那么它是单调的。
如果对于所有 i <= j,A[i] <= A[j],那么数组 A 是单调递增的。 如果对于所有 i <= j,A[i]> = A[j],那么数组 A 是单调递减的。
当给定的数组 A 是单调数组时返回 true,否则返回 false。
输入:[1,2,2,3] 输出:true
输入:[6,5,4,4] 输出:true
输入:[1,3,2] 输出:false
输入:[1,2,4,5] 输出:true
输入:[1,1,1] 输出:true
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/monotonic-array 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered:
没什么说的
func isMonotonic(A []int) bool { if len(A) == 1 { return true } if A[0] == A[len(A)-1] { for i := 1; i < len(A); i++ { if A[i] != A[i-1] { return false } } } else if A[0] > A[len(A)-1] { for i := 1; i < len(A); i++ { if A[i] > A[i-1] { return false } } } else { for i := 1; i < len(A); i++ { if A[i] < A[i-1] { return false } } } return true }
Sorry, something went wrong.
No branches or pull requests
如果数组是单调递增或单调递减的,那么它是单调的。
如果对于所有 i <= j,A[i] <= A[j],那么数组 A 是单调递增的。 如果对于所有 i <= j,A[i]> = A[j],那么数组 A 是单调递减的。
当给定的数组 A 是单调数组时返回 true,否则返回 false。
示例 1:
示例 2:
示例 3:
示例 4:
示例 5:
提示:
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/monotonic-array
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered: