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

Commit 4972684

Browse files
committed
896 finish
1 parent 795dfda commit 4972684

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
package problem0896
22

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

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
11+
return inc || dec
2512
}

0 commit comments

Comments
 (0)