"""
:type nums: List[int]
:rtype: int
"""
class Solution(object):
def maxSubArray(self, nums):
# For the case of 'No elements' in 'nums',
# you have to write this code..!
# If there is no this code? It will make error.
if not nums:
return 0
# To make 'reset', you have to write this code
# to prevent for 'resetting again' problem.
cur_sum = max_sum = nums[0]
# For making 'update' for max_sum(=the answer of this problem),
# You have to write this code.
for i in range(1, len(nums)):
cur_sum = max(nums[i], cur_sum + nums[i])
max_sum = max(cur_sum, max_sum)
return max_sum
댓글남기기