53. Maximum Subarray

2025. 10. 7. 16:10Algorithm/Leetcode, Lintcode, HackerRank, etc.

    목차
반응형
    def maxSubArray(self, nums: List[int]) -> int:
        tot = 0
        mx = float('-inf')

        for num in nums:
            if tot + num > num:
                tot += num
            else:
                tot = num

            mx = max(mx, tot)

        return mx
반응형