标签:i++ solution public list subarray return imu alt lis
class Solution {
public:
/*
* @param nums: a list of integers
* @return: A integer indicate the sum of minimum subarray
*/
int minSubArray(vector<int> &nums) {
// write your code here
int sum = 0, flag = 0;
for (int i = 0; i < nums.size(); i++) {
flag += nums[i];
if (flag > 0) flag = 0;
if (flag < sum) sum = flag;
}
sort(nums.begin(), nums.end());
if (nums[0] >= 0) {
sum = nums[0];
}
return sum;
}
};
标签:i++ solution public list subarray return imu alt lis
原文地址:http://www.cnblogs.com/ye-chen/p/7789235.html