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;
}
};
时间: 2024-10-10 16:43:04