728x90
class Solution:
# @param A, a list of integers
# @return an integer
# 6:57
def maxSubArray(self, A):
if not A:
return 0
curSum = maxSum = A[0]
for num in A[1:]:
curSum = max(num, curSum + num) # max(current index value, current max sub array w/ current idx value)
maxSum = max(maxSum, curSum) # get each sub array's max sub array
return maxSum
www.youtube.com/watch?time_continue=487&v=2MmGzdiKR9Y&feature=emb_logo
출처: leetcode.com/problems/maximum-subarray/discuss/20194/A-Python-solution
728x90
'Leetcode' 카테고리의 다른 글
198. House Robber (0) | 2020.08.16 |
---|---|
303. Range Sum Query - Immutable (0) | 2020.08.16 |
70. Climbing Stairs (0) | 2020.08.15 |
392. Is Subsequence (0) | 2020.08.15 |
121. Best Time to Buy and Sell Stock (0) | 2020.08.10 |
댓글