Skip to content

Commit 89d44ea

Browse files
committed
Add solution 896
1 parent 516760d commit 89d44ea

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

896_MonotonicArray.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
func isMonotonic(_ A: [Int]) -> Bool {
3+
if A.count <= 1 {
4+
return true
5+
}
6+
7+
let increased = A[A.count-1] >= A[0]
8+
for i in 1..<A.count {
9+
if A[i] == A[i-1] {
10+
continue
11+
}
12+
let isIncreasing = A[i] >= A[i-1]
13+
if isIncreasing != increased {
14+
return false
15+
}
16+
}
17+
return true
18+
}
19+
}

0 commit comments

Comments
 (0)