Author: | aaa |
---|---|
Mode: | c++ |
Date: | Fri, 26 Aug 2022 03:21:28 |
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; } };