- O(1)空间复杂度, O(N)空间复杂度
class Solution {
public:
int FindGreatestSumOfSubArray(vector<int> array) {
int size = array.size();
int ans=array[0];
int dpi = array[0];
int dpip1 = 0;
for(int i=0; i<size-1; i++){
dpip1 = array[i+1]+(dpi<0?0:dpi);
ans = dpip1>ans?dpip1:ans;
dpi = dpip1;
}
return ans;
}
};