mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Merge ce15f5921f
into f3f32ae3ca
This commit is contained in:
commit
1a7c711881
|
@ -9,6 +9,16 @@ def is_monotonic(nums: list[int]) -> bool:
|
||||||
True
|
True
|
||||||
>>> is_monotonic([1, 3, 2])
|
>>> is_monotonic([1, 3, 2])
|
||||||
False
|
False
|
||||||
|
>>> is_monotonic([1,2,3,4,5,6,5])
|
||||||
|
False
|
||||||
|
>>> is_monotonic([-3,-2,-1])
|
||||||
|
True
|
||||||
|
>>> is_monotonic([-5,-6,-7])
|
||||||
|
True
|
||||||
|
>>> is_monotonic([0,0,0])
|
||||||
|
True
|
||||||
|
>>> is_monotonic([-100,0,100])
|
||||||
|
True
|
||||||
"""
|
"""
|
||||||
return all(nums[i] <= nums[i + 1] for i in range(len(nums) - 1)) or all(
|
return all(nums[i] <= nums[i + 1] for i in range(len(nums) - 1)) or all(
|
||||||
nums[i] >= nums[i + 1] for i in range(len(nums) - 1)
|
nums[i] >= nums[i + 1] for i in range(len(nums) - 1)
|
||||||
|
@ -21,3 +31,7 @@ if __name__ == "__main__":
|
||||||
print(is_monotonic([1, 2, 2, 3])) # Output: True
|
print(is_monotonic([1, 2, 2, 3])) # Output: True
|
||||||
print(is_monotonic([6, 5, 4, 4])) # Output: True
|
print(is_monotonic([6, 5, 4, 4])) # Output: True
|
||||||
print(is_monotonic([1, 3, 2])) # Output: False
|
print(is_monotonic([1, 3, 2])) # Output: False
|
||||||
|
|
||||||
|
import doctest
|
||||||
|
|
||||||
|
doctest.testmod()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user