forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAC_dp_n.cpp
More file actions
36 lines (30 loc) · 681 Bytes
/
AC_dp_n.cpp
File metadata and controls
36 lines (30 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_dp_n.cpp
* Create Date: 2014-12-24 11:16:17
* Descripton: dp
* http://blog.csdn.net/hcbbt/article/details/10454947
* the way 4
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
public:
int maxSubArray(int A[], int n) {
if (n == 0)
return 0;
int sum = A[0], mmax = A[0];
for (int i = 1; i < n; i++) {
if (sum < 0)
sum = A[i];
else
sum += A[i];
mmax = max(mmax, sum);
}
return mmax;
}
};
int main() {
return 0;
}