Yet Another Off By One Error

This commit is contained in:
Dan Buch 2023-10-28 08:24:17 -04:00
parent 3580198513
commit 01a189c5ee
Signed by: meatballhat
GPG Key ID: A12F782281063434
2 changed files with 5 additions and 1 deletions

View File

@ -544,7 +544,7 @@ def sum_max_sub_array(nums: list[int]) -> int:
max_sum: int = sum(nums) max_sum: int = sum(nums)
while end - begin <= len(nums): while end - begin <= len(nums):
while end < len(nums): while end <= len(nums):
max_sum = max(max_sum, sum(nums[begin:end])) max_sum = max(max_sum, sum(nums[begin:end]))
begin += 1 begin += 1
end += 1 end += 1

View File

@ -461,6 +461,10 @@ def test_trie_busy():
[5, 4, -1, 7, 8], [5, 4, -1, 7, 8],
23, 23,
), ),
(
[-2, 1],
1,
),
], ],
) )
def test_maximum_subarray(nums: list[int], expected: int): def test_maximum_subarray(nums: list[int], expected: int):