链接:剑指 Offer 42. 连续子数组的最大和
题解:
class Solution { public: int maxSubArray(vector<int>& nums) { int res = INT_MIN; int sum = 0; for (auto num : nums) { sum += num; res = max(res, sum); if (sum < 0) { sum = 0; } } return res; } };