Leetcode-53/220322


https://leetcode.com/problems/maximum-subarray/

Python

class Solution:
    def maxSubArray(self, nums: List[int]) -> int:
        for i in range(1, len(nums)):
            if nums[i-1] > 0:
                nums[i] += nums[i-1]
        return max(nums)
連続値の和の中で最大値を求める問題.
num[i]の前の値が正の場合の加算方法