17 lines
348 B
Python
17 lines
348 B
Python
from math import inf
|
|
|
|
def maxSubArray(nums):
|
|
max_sum = nums[0]
|
|
current_sum = nums[0]
|
|
|
|
for n in nums[1:]:
|
|
if current_sum < 0:
|
|
current_sum = 0
|
|
current_sum += n
|
|
if current_sum > max_sum:
|
|
max_sum = current_sum
|
|
return max_sum
|
|
|
|
if __name__ == "__main__":
|
|
print(maxSubArray([-2,1]))
|