"""
Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.
Example:
Input: s = 7, nums = [2,3,1,2,4,3]
Output: 2
Explanation: the subarray [4,3] has the minimal length under the problem constraint.
"""
"""
滑动窗口,与leetcode713类似
"""
class Solution:
def minSubArrayLen(self, s: int, nums):
_sum = 0
res = len(nums) + 1
i = 0
for j in range(len(nums)):
_sum += nums[j]
while _sum >= s: #!!!
res = min(res, j-i+1)
_sum -= nums[i]
i += 1
return res if res <= len(nums) else 0

最新文章

  1. Clr Via C#读书笔记---程序集的加载和反射
  2. 【转】如果成为一个牛比的BI售前
  3. Go视频教程整理
  4. ctl 里面pdef解说
  5. 课堂所讲整理:输入输出流(I/O)
  6. ==和equals()的用法
  7. iOS 定位服务、通讯录、日历、提醒事项、照片、蓝牙共享、麦克风、相机等授权检测
  8. ARM处理器:开放者的逆袭
  9. 1491: [NOI2007]社交网络
  10. PHP安装sqlsrv扩展步骤,PHP如何连接上SQL
  11. 最新Windows下Redis集群
  12. java-HashMap默认机制
  13. Surjectivity is stable under base change
  14. linux nfs远程挂载和卸载
  15. 【转载】 PhpStudy修改Apache的端口号
  16. Jsの数组练习-求一组数中的最大值和最小值,以及所在位置
  17. C#检测U盘是否插入
  18. 实现 AD 采样,使用 LCD1602 显示 AD 数值
  19. CorelDRAW X4常用快捷键大全
  20. UE查找和替换技巧实例

热门文章

  1. AtCoDeer and Election Report
  2. Java面向对象private
  3. 本地缓存Caffeine
  4. python序列的拆分
  5. ASP.NET Core搭建多层网站架构【4-工作单元和仓储设计】
  6. map的使用-Hdu 2648
  7. Centos7 虚拟环境安装Django 出现ImproperlyConfigured(&#39;SQLite 3.8.3 or later is required (found %s).&#39; %Database.sqlite_version)错误
  8. spring 参数校验
  9. windows 配置hadoop环境
  10. 201771010135杨蓉庆《面向对象程序设计(java)》第六周学习总结