From b74a7d1f7bb809dbe0e16560770ad49e93f75d37 Mon Sep 17 00:00:00 2001 From: Melih Mehmet Sahin Date: Mon, 14 Oct 2024 20:58:51 +0100 Subject: [PATCH 1/2] Contributes to #9943 with monotonic_array.py Contributes to #9943 by adding doctests, including negative numbers and an array of same integers. --- data_structures/arrays/monotonic_array.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/data_structures/arrays/monotonic_array.py b/data_structures/arrays/monotonic_array.py index c50a21530814..b6e0b7e16396 100644 --- a/data_structures/arrays/monotonic_array.py +++ b/data_structures/arrays/monotonic_array.py @@ -1,3 +1,5 @@ +import doctest + # https://leetcode.com/problems/monotonic-array/ def is_monotonic(nums: list[int]) -> bool: """ @@ -9,6 +11,16 @@ def is_monotonic(nums: list[int]) -> bool: True >>> is_monotonic([1, 3, 2]) 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( nums[i] >= nums[i + 1] for i in range(len(nums) - 1) @@ -21,3 +33,5 @@ def is_monotonic(nums: list[int]) -> bool: print(is_monotonic([1, 2, 2, 3])) # Output: True print(is_monotonic([6, 5, 4, 4])) # Output: True print(is_monotonic([1, 3, 2])) # Output: False + + doctest.testmod() From 8bb56cf27d4edca4cbc033ed2116d5468334c43c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 20:01:40 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/monotonic_array.py | 1 + 1 file changed, 1 insertion(+) diff --git a/data_structures/arrays/monotonic_array.py b/data_structures/arrays/monotonic_array.py index b6e0b7e16396..729c63b0df46 100644 --- a/data_structures/arrays/monotonic_array.py +++ b/data_structures/arrays/monotonic_array.py @@ -1,5 +1,6 @@ import doctest + # https://leetcode.com/problems/monotonic-array/ def is_monotonic(nums: list[int]) -> bool: """