LeetCode 53、剑指Offer42 都是求 连续子序列的最大和,
https://leetcode.com/problems/maximum-subarray/
class Solution {
public:int maxSubArray(vector<int>& nums) {int val = nums[0];int sum = val;int n = nums.size();for(int i=1;i<n;i++){if(val>0 && nums[i] + val > 0)val = nums[i]+val;else// if(nums[i]>=0 && val<=0)val = nums[i];sum = max(sum, val);}return sum;}
};
来自杭电OJ 1231这道题,不仅求最大和&