본문 바로가기

⏳ 알고리즘/python 알고리즘 문제 풀이

리트코드 - 53. Maximum Subarray

문제

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

 

Maximum Subarray - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

코드

1) 메모이제이션

class Solution: 
    def maxSubArray(self, nums: List[int]) -> int:
        for i in range(1, len(nums)):
            nums[i] += nums[i-1] if nums[i-1]>0 else 0
            
        return max(nums)