896. Monotonic Array
❀ Origin
Problem
An array is monotonic if it is either monotone increasing or monotone decreasing.
An array A is monotone increasing if for all i <= j, A[i] <= A[j].
An array A is monotone decreasing if for all i <= j, A[i] >= A[j].
Return true if and only if the given array A is monotonic.
Note
- 1 <= A.length <= 50000
- -100000 <= A[i] <= 100000
Example 1
1 | Input: [1,2,2,3] |
Example 2
1 | Input: [6,5,4,4] |
Example 3
1 | Input: [1,3,2] |
Example 4
1 | Input: [1,2,4,5] |
Example 5
1 | Input: [1,1,1] |
❀ 翻譯
問題
如果是單調的遞增或單調遞減,則這是個單調陣列
如果所有 i <= j, A[i] <= A[j] ,則 A 陣列為單調。
如果所有 i <= j, A[i] >= A[j] ,則 A 陣列為單調。
只有當給定的陣列 A 為單調時,才回傳 true 。
注意
- 1 <= A.length <= 50000
- -100000 <= A[i] <= 100000
❀ Solution
Golang
1 | package problem0896 |