Skip to content

Commit fe95d37

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent d81ef30 commit fe95d37

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

dynamic_programming/max_sub_array.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
from __future__ import annotations
66

7+
78
def max_sub_array(nums: list[int]) -> int:
89
"""
910
Finds the contiguous subarray which has the largest sum and return its sum.
@@ -26,15 +27,15 @@ def max_sub_array(nums: list[int]) -> int:
2627
>>> max_sub_array([10, 100, 1000, 10000, 50000, 100000, 200000, 300000, 400000, 500000])
2728
1561110
2829
"""
29-
sol = [0]* (len(a) + 1)
30+
sol = [0] * (len(a) + 1)
3031
for i in range(1, len(sol)):
31-
sol[i] = max(sol[i - 1] + a[i -1], a[i - 1])
32-
33-
answer = sol[0]
32+
sol[i] = max(sol[i - 1] + a[i - 1], a[i - 1])
33+
34+
answer = sol[0]
3435
for i in range(1, len(sol)):
3536
if answer < sol[i]:
3637
answer = sol[i]
37-
return answer
38+
return answer
3839

3940

4041
if __name__ == "__main__":

0 commit comments

Comments
 (0)