题解 | 最大子数组和

最大子数组和

https://www.nowcoder.com/practice/c158a2b2476145acb001ac711fe73a78

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    int t;
    cin >> t;
    int z_max = t,c_max = t; 
    for (int i = 1; i < n; i++) {
        cin >> t;
        c_max = max(t, c_max + t);
        z_max = max(z_max, c_max);
    }
    cout << z_max;
    return 0;
}

全部评论

相关推荐

烤点老白薯:感觉这女生 有上位者的甲方心态 不适合处对象 也不清楚自己的竞争力 整得他有多懂似的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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