Skip to content

Commit

Permalink
Create 1-复杂度1 最大子列和问题 (20 分).cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
hao14293 authored May 1, 2019
1 parent c875445 commit 7dd4209
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
using namespace std;

int main(){
int k, sum = 0, maxSum = 0;
cin >> k;
for(int i = 0; i < k; i++){
int temp;
cin >> temp;
sum += temp;
if(sum < 0) sum = 0;
if(sum > maxSum) maxSum = sum;
}
cout << maxSum;
return 0;
}

0 comments on commit 7dd4209

Please sign in to comment.