[leetcode刷题系列]Maximun Subarray

经典的DP题目了,没啥好说的

class Solution {
public:
    int maxSubArray(int A[], int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        int ans = A[0];
        for(int i = 1; i < n; ++ i)
            ans = max(ans, A[i] = max(A[i], A[i] + A[i - 1]));
        return ans;
    }
};


你可能感兴趣的:([leetcode刷题系列]Maximun Subarray)