209. Minimum Size Subarray Sum
2016-07-18 06:56
387 查看
209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array
[2,3,1,2,4,3]and
s = 7,
the subarray
[4,3]has the minimal length under the problem constraint.
Hide Tags
Array Two Pointers Binary Search
Hide Similar Problems
(H) Minimum Window Substring (M) Maximum Size Subarray Sum Equals k
public class Solution { public int minSubArrayLen(int s, int[] nums) { int sum = 0; int ret = Integer.MAX_VALUE; int begin = 0; int end = 0; while(end<nums.length) { sum += nums[end++]; while(sum >= s){ ret = Math.min(ret, end - begin); sum -= nums[begin++]; } } return ret == Integer.MAX_VALUE ? 0 : ret; } }
相关文章推荐
- BaseServlet第一版
- 卖小众精品男装很出名的王牌先生 想众筹一个“美好实验室”·每日商报
- Boot from Volume - 每天5分钟玩转 OpenStack(61)
- Boot from Volume - 每天5分钟玩转 OpenStack(61)
- Boot from Volume - 每天5分钟玩转 OpenStack(61)
- 第二周 7.18 --- 7.24
- 【会员动态】2015ADM | 王牌先生,带你体验当代绅士的生活美学-浙江省创意设计协会-微头条(wtoutiao.com)
- 【独家】专注男士着装搭配服务,王牌先生获华旦领投近500万天使融资 | 猎云网
- Tomcat解决中文乱码的几种方式
- ViewPager中的PagerTabStrip在运行测试的时候不显示问题解决
- jar打包命令详解
- Webkaching.kr的Wp(更新中)
- 将树莓派所撷取 sensor 数据存入 Bluemix Cloudant NoSQL database
- Haffman Encoding and Decoding
- Java虚拟机知识整理——垃圾的判断
- 源码推荐(0718):录音封装直接拿来用,关于多界面的操作
- 实习分享之腾讯HR面以及总结 (搬运工)
- 30. Substring with Concatenation of All Words && 76. Minimum Window Substring
- 实习分享之腾讯二面(搬运工)
- 实习分享之腾讯一面(搬运工)