One more thought about max sub-array
This commit is contained in:
parent
cb68a35b1b
commit
db38eeada9
@ -550,6 +550,19 @@ def sum_max_sub_array(nums: list[int]) -> int:
|
||||
return mmax
|
||||
|
||||
|
||||
def sum_max_sub_array_i(nums: list[int]) -> tuple[int, int]:
|
||||
mmax_i: int = 0
|
||||
mmax = last = prev = nums[0]
|
||||
|
||||
for i in range(1, len(nums)):
|
||||
prev = nums[i] + last
|
||||
last = max(nums[i], prev)
|
||||
mmax_i = i if last > mmax else mmax_i
|
||||
mmax = max(mmax, last)
|
||||
|
||||
return mmax_i, mmax
|
||||
|
||||
|
||||
def sum_max_sub_array_accum(nums: list[int]) -> int:
|
||||
accum: list[int] = [nums[0]]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user