Paste: 最大子数组

Author: aaa
Mode: c++
Date: Fri, 26 Aug 2022 03:21:28
Plain Text |
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int res = nums[0], prev = 0, curr = 0; 
        for (int n : nums) {
            curr = max(n, prev + n); 
            res = max(res, curr); 
            prev = curr; 
        } 
        return res; 
    }
};

New Annotation

Summary:
Author:
Mode:
Body: