Scribbling

LeetCode: 53. Maximum Subarray 본문

Computer Science/Coding Test

LeetCode: 53. Maximum Subarray

focalpoint 2021. 9. 24. 12:04
class Solution:
    def maxSubArray(self, nums: List[int]) -> int:
        ret = -int(1e9)
        now = 0
        for num in nums:
            now += num
            ret = max(ret, now)
            if now <= 0:
                now = 0
        return ret

 

'Computer Science > Coding Test' 카테고리의 다른 글

LeetCode: 60. Permutation Sequence  (0) 2021.09.24
LeetCode: 59. Spiral Matrix II  (0) 2021.09.24
LeetCode: 57. Insert Interval  (0) 2021.09.24
LeetCode: 56. Merge Intervals  (0) 2021.09.23
LeetCode: 54. Spiral Matrix  (1) 2021.09.17