Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 795dfda

Browse files
committed
896 accepted
1 parent 0c86321 commit 795dfda

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
package problem0896
22

33
func isMonotonic(A []int) bool {
4+
return isMonotoneIncreasing(A) || isMonotoneDecreasing(A)
5+
}
6+
7+
func isMonotoneIncreasing(A []int) bool {
8+
size := len(A)
9+
for i := 1; i < size; i++ {
10+
if A[i-1] > A[i] {
11+
return false
12+
}
13+
}
14+
return true
15+
}
416

5-
return false
17+
func isMonotoneDecreasing(A []int) bool {
18+
size := len(A)
19+
for i := 1; i < size; i++ {
20+
if A[i-1] < A[i] {
21+
return false
22+
}
23+
}
24+
return true
625
}

0 commit comments

Comments
 (0)