LeetCode-53 最大子数组和
Table of Contents
LeetCode-53 最大子数组和 #
Solution 1 #
经典动态规划问题.
代码如下:
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
ans = -inf
s = 0
for x in nums:
s = max(s, 0) + x
ans = max(ans, s)
return ans