1 class Solution {
 2 public:
 3     int maxSubArray(int A[], int n) {
 4         // Start typing your C/C++ solution below
 5         // DO NOT write int main() function
 6         int result;
 7         if (n == 0) return result;
 8         
 9         vector <int> record(n,0);
10         record[0] = A[0];
11         result = record[0];
12         
13         for (int i=0; i<n-1; i++){
14             
15             record[i+1] = max(record[i]+A[i+1], A[i+1]);
16             if (record[i+1] > result) result = record[i+1];
17         }
18         
19         return result;
20     }
21 };

 

posted on 2013-05-14 02:08  tanghulu321  阅读(95)  评论(0编辑  收藏  举报