Skip to content

Commit 9af82bd

Browse files
committed
base case kadane
1 parent 8e8ff00 commit 9af82bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

misc/kadane.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ def find_max_subarray(numbers):
1212

1313
def find_max_subarray2(numbers):
1414
""" shorter version """
15-
max_till_here = [0]
16-
for n in numbers:
15+
if len(numbers) == 0:
16+
return 0
17+
max_till_here = [numbers[0]]
18+
for n in numbers[1:]:
1719
max_till_here.append(max(n, max_till_here[-1] + n))
1820
return max(max_till_here)
1921

0 commit comments

Comments
 (0)