solution.cpp 330 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
	int maxSubArray(vector<int> &nums)
	{
		int sum = 0, max_sum = INT_MIN;
		for (int i = 0; i < nums.size(); i++)
		{
			if (sum < 0)
			{
				sum = nums[i];
			}
			else
			{
				sum += nums[i];
			}
			max_sum = max(sum, max_sum);
		}
		return max_sum;
	}
};