LintCode_044_最小子数组
2017-12-17 20:29
288 查看
问题描述
给定一个整数数组,找到一个具有最小和的子数组。返回其最小和。样例
给出数组[1, -1, -2, 1],返回 -3求解
class Solution { public: int minSubArray(vector<int> &nums) { int minSum = 0; int curSum = 0; for (auto it = nums.begin(); it != nums.end(); ++it) { if (it == nums.begin()) { minSum = *it; } curSum += *it; if (curSum < minSum) { minSum = curSum; } if (curSum > 0) { curSum = 0; } } return minSum; } };
相关文章推荐
- LintCode_044_最小子数组
- lintcode-44-最小子数组
- LintCode: 最小子数组
- LintCode: 和大于S的最小子数组
- LintCode--最小子数组
- lintcode 44.最小子数组
- Lintcode最小子数组
- lintcode 容易题:Minimum Subarray 最小子数组
- lintcode编程题 java实现:(一)和大于S的最小子数组
- lintcode最小子数组
- LintCode:M-和大于S的最小子数组
- Lintcode-贪心-最大子数组和最小子数组
- LintCode -- 最大子数组 III
- LINTCODE——最大子数组III
- Lintcode 两个排序数组的中位数
- lintcode&九章算法——Google 面试题 | 3个非重复子数组最大和
- lintcode之数组划分
- lintcode: 把排序数组转换为高度最小的二叉搜索树
- LintCode Merge Sorted ArrayII 合并排序数组 II
- lintcode-搜索旋转排序数组-62