Leetcode
53. Maximum Subarray
YGSEO
2020. 8. 16. 00:49
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