-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmonotonic-array.py
More file actions
35 lines (23 loc) · 812 Bytes
/
monotonic-array.py
File metadata and controls
35 lines (23 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from typing import List
class Solution:
def isMonotonic(self, A: List[int]) -> bool:
direction = A[0] <= A[-1]
for pos in range(1, len(A)):
if direction != (A[pos - 1] <= A[pos]) and A[pos - 1] != A[pos]:
return False
return True
class TestSolution:
def setup(self):
self.sol = Solution()
def test_one(self):
assert self.sol.isMonotonic([1])
def test_case1(self):
assert self.sol.isMonotonic([1, 2, 2, 3])
def test_case2(self):
assert self.sol.isMonotonic([6, 5, 4, 4])
def test_case3(self):
assert not self.sol.isMonotonic([1, 3, 2])
def test_case4(self):
assert self.sol.isMonotonic([1, 2, 4, 5])
def test_case5(self):
assert self.sol.isMonotonic([1, 1, 1])