题解 | #连续子数组最大和#

连续子数组最大和

https://www.nowcoder.com/practice/1718131e719746e9a56fb29c40cc8f95

import sys

n = list(map(int,input().split()))[0]
arr = list(map(int,input().split()))
dp = []

for i in range(n):
    if i ==0:
        dp.append(arr[i])
    else:
        dp.append(max(arr[i],(dp[i-1]+arr[i])))

print(max(dp))

思路挺难想,代码挺简单

全部评论

相关推荐

头像
05-27 20:32
已编辑
深度学习
工行数据中心 偏运维养老 到手可能18w
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务