diff --git a/leetcode/stuff.py b/leetcode/stuff.py index 71761f9..6d0f463 100644 --- a/leetcode/stuff.py +++ b/leetcode/stuff.py @@ -544,7 +544,7 @@ def sum_max_sub_array(nums: list[int]) -> int: max_sum: int = sum(nums) while end - begin <= len(nums): - while end < len(nums): + while end <= len(nums): max_sum = max(max_sum, sum(nums[begin:end])) begin += 1 end += 1 diff --git a/leetcode/test_stuff.py b/leetcode/test_stuff.py index 8a2555d..9064ab9 100644 --- a/leetcode/test_stuff.py +++ b/leetcode/test_stuff.py @@ -461,6 +461,10 @@ def test_trie_busy(): [5, 4, -1, 7, 8], 23, ), + ( + [-2, 1], + 1, + ), ], ) def test_maximum_subarray(nums: list[int], expected: int):