#牛客在线求职答疑中心# 请用python解答如下问题
给定一个整数数组 nums,任务是找到一个具有最大和的连续子数组(至少包含一个元素),并返回这个最大和。
例如:nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
全部评论
class Solution: def maxSubArray(self, nums: List[int]) -> int: ans = min(nums) count = 0 for i in nums: count+=i if count>ans: ans=count if count<0: count=0 return ans
点赞 回复 分享
发布于 2024-09-21 13:46 四川

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务