题目

给定一个整数数组,找到一个具有最小和的子数组。返回其最小和。

注意事项

子数组最少包含一个数字

样例

给出数组[1, -1, -2, 1],返回 -3

思路

动态规划解决

C++代码

 int minSubArray(vector<int> nums) {
// write your code here
int s, min;
int len = nums.size();
if(len == ) return ;
int i;
min = nums[];
s = nums[];
for(i = ; i < len; ++i)
{
if(s > ) s = nums[i];
else s += nums[i];
min = min > s ? s : min;
}
return min;
}

LintCode_44 最小子数组的更多相关文章

  1. Windows10系统如何安装Microsoft Visual Studio 2015及最小子数组和求解

    一.Windows10系统如何安装Microsoft Visual Studio 2015. 1.首先到Visual Studio官方网站(https://www.visualstudio.com/v ...

  2. lintcode 中等题:和大于S的最小子数组

    题目 和大于S的最小子数组 给定一个由 n 个整数组成的数组和一个正整数 s ,请找出该数组中满足其和 ≥ s 的最小长度子数组.如果无解,则返回 -1. 样例 给定数组 [2,3,1,2,4,3]  ...

  3. lintcode:Minimum Subarray 最小子数组

    题目: 最小子数组 给定一个整数数组,找到一个具有最小和的子数组.返回其最小和. 样例 给出数组[1, -1, -2, 1],返回 -3 注意 子数组最少包含一个数字 解题: 和最大子数组 ,差不多的 ...

  4. lintcode.44 最小子数组

    最小子数组   描述 笔记 数据 评测 给定一个整数数组,找到一个具有最小和的子数组.返回其最小和. 注意事项 子数组最少包含一个数字 您在真实的面试中是否遇到过这个题? Yes 哪家公司问你的这个题 ...

  5. 求数组中的最小子数组,时间复杂度o(n),java

    石家庄铁道大学 信1405-1 班 唐炳辉 题目:给定一个整数数组,找到一个具有最小和的子数组.返回其最小和. 设计思路:两个变量 ,一个记录当前并入的数组的值,另外一个记录所算过得最大的数组的值,当 ...

  6. 和大于S的最小子数组 · Minimum Size Subarray Sum

    [抄题]: 给定一个由 n 个正整数组成的数组和一个正整数 s ,请找出该数组中满足其和 ≥ s 的最小长度子数组.如果无解,则返回 -1. 给定数组 [2,3,1,2,4,3] 和 s = 7, 子 ...

  7. LeetCode OJ:Minimum Size Subarray Sum(最小子数组的和)

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  8. [LintCode] Minimum Size Subarray Sum 最小子数组和的大小

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  9. [LeetCode] Maximum Product Subarray 求最大子数组乘积

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

随机推荐

  1. input光标使用caret-color改变颜色

    本文转载自:https://www.zhangxinxu.com/wordpress/2018/01/css-caret-color-first-line/ CSS caret-color属性可以改变 ...

  2. 单体内置对象——Global对象

    单体内置对象的定义:由ECMAScript实现提供的.不依赖于宿主环境的对象,这些对象在ECMAScript程序执行之前已经存在了.意思就是说:开发人员不必显式地实例化内置对象,因为他们已经实例化了. ...

  3. react之可控组件与不可控组件

    一.不可控组件 <input type="text" defaultvalue="Hello React" /> 如上:defaultvalue的值 ...

  4. wordpress 插件语法分析器

    在通过查看 apply_filters( 'ap_addon_form_args', array $form_args ) 的html body class中发现wp-parser 字样,就googl ...

  5. python Mean Squared Error vs. Structural Similarity Measure两种算法的图片比较

    # by movie on 2019/12/18 import matplotlib.pyplot as plt import numpy as np from skimage import meas ...

  6. C++ 标准文件的写入读出(ifstream,ofstream)

    ttp://blog.csdn.net/a125930123/article/details/53542261     注: "<<", 插入器,向流输入数据     ...

  7. 33 N皇后问题

    原题网址:https://www.lintcode.com/zh-cn/old/problem/n-queens/# n皇后问题是将n个皇后放置在n*n的棋盘上,皇后彼此之间不能相互攻击. 给定一个整 ...

  8. PAT甲级——A1005 Spell It Right

    题目描述 Given a non-negative integer N, your task is to compute the sum of all the digits of N, and out ...

  9. Spring注解驱动(下)

    9.@PropertySource 加载配置文件 在xml中 我们加载property配置文件,是使用 <context:property-placeholder location=" ...

  10. 04_Hibernate检索方式

    一.Hibernate检索方式概述 OID检索方式:按照对象的OID来检索对象(get/load) HQL检索方式:使用面向对象的HQL查询语言 QBC检索方式:使用QBC(Query By Crit ...