LeetCode 53. Maximum Subarray - Python

preview_player
Показать описание
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

A subarray is a contiguous part of an array.
Рекомендации по теме
Комментарии
Автор

class Solution:
def maxSubArray(self, nums: List[int]) -> int:

for idx in range(1, len(nums)):
if nums[idx-1] > 0:
nums[idx] += nums[idx-1]

return max(nums)

maged_helmy
welcome to shbcf.ru