标签:images amp list sum cto png tor size integer
class Solution {
public:
/*
* @param nums: A list of integers
* @return: A integer indicate the sum of max subarray
*/
int maxSubArray(vector<int> &nums) {
// write your code here
int sum = 0, flag = 0,n=nums.size();
for (int i = 0; i < n; i++) {
flag += nums[i];
if (flag < 0) flag = 0;
if (flag > sum) sum = flag;
}
sort(nums.begin(), nums.end());
if (nums[n-1] <= 0) {
sum = nums[n-1];
}
return sum;
}
};
标签:images amp list sum cto png tor size integer
原文地址:http://www.cnblogs.com/ye-chen/p/7789214.html