class Solution:
def maxSubArray(self, nums: [int]) -> int:
res = nums[0]
res_max = res
for num in nums[1:]:
res = num if res < 0 else res + num
res_max = max(res_max, res)
return res_max
LeetCode 53. Maximum Subarray 时间复杂度(O(n))
最新推荐文章于 2024-11-01 15:19:21 发布