Skip to content

Commit b74a7d1

Browse files
authored
Contributes to #9943 with monotonic_array.py
Contributes to #9943 by adding doctests, including negative numbers and an array of same integers.
1 parent e9e7c96 commit b74a7d1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

data_structures/arrays/monotonic_array.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import doctest
2+
13
# https://leetcode.com/problems/monotonic-array/
24
def is_monotonic(nums: list[int]) -> bool:
35
"""
@@ -9,6 +11,16 @@ def is_monotonic(nums: list[int]) -> bool:
911
True
1012
>>> is_monotonic([1, 3, 2])
1113
False
14+
>>> is_monotonic([1,2,3,4,5,6,5])
15+
False
16+
>>> is_monotonic([-3,-2,-1])
17+
True
18+
>>> is_monotonic([-5,-6,-7])
19+
True
20+
>>> is_monotonic([0,0,0])
21+
True
22+
>>> is_monotonic([-100,0,100])
23+
True
1224
"""
1325
return all(nums[i] <= nums[i + 1] for i in range(len(nums) - 1)) or all(
1426
nums[i] >= nums[i + 1] for i in range(len(nums) - 1)
@@ -21,3 +33,5 @@ def is_monotonic(nums: list[int]) -> bool:
2133
print(is_monotonic([1, 2, 2, 3])) # Output: True
2234
print(is_monotonic([6, 5, 4, 4])) # Output: True
2335
print(is_monotonic([1, 3, 2])) # Output: False
36+
37+
doctest.testmod()

0 commit comments

Comments
 (0)