题解 | 最大子数组和
最大子数组和
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;
}
凡岛公司福利 799人发布
查看20道真题和解析