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

连续子数组最大和

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))

思路挺难想,代码挺简单

全部评论

相关推荐

点赞 评论 收藏
分享
10-22 19:44
门头沟学院 Java
面了100年面试不知...:那我得去剪个头
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务