[리트코드] Maximum Subarray

박형진·2022년 1월 27일
0

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


1. 전체 코드

class Solution:
    def maxSubArray(self, nums: List[int]) -> int:
        ans = float('-inf')
        current_value = 0
        for num in nums:
            current_value = max(num, current_value + num)
            ans = max(current_value, ans)


s = Solution()
s.maxSubArray([-2, 1, -3, 4, -1, 2, 1, -5, 4])
profile
안녕하세요!

0개의 댓글