leetcode209 Minimum Size Subarray Sum
2024-09-04 11:29:41
"""
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
最新文章
- Clr Via C#读书笔记---程序集的加载和反射
- 【转】如果成为一个牛比的BI售前
- Go视频教程整理
- ctl 里面pdef解说
- 课堂所讲整理:输入输出流(I/O)
- ==和equals()的用法
- iOS 定位服务、通讯录、日历、提醒事项、照片、蓝牙共享、麦克风、相机等授权检测
- ARM处理器:开放者的逆袭
- 1491: [NOI2007]社交网络
- PHP安装sqlsrv扩展步骤,PHP如何连接上SQL
- 最新Windows下Redis集群
- java-HashMap默认机制
- Surjectivity is stable under base change
- linux nfs远程挂载和卸载
- 【转载】 PhpStudy修改Apache的端口号
- Jsの数组练习-求一组数中的最大值和最小值,以及所在位置
- C#检测U盘是否插入
- 实现 AD 采样,使用 LCD1602 显示 AD 数值
- CorelDRAW X4常用快捷键大全
- UE查找和替换技巧实例
热门文章
- AtCoDeer and Election Report
- Java面向对象private
- 本地缓存Caffeine
- python序列的拆分
- ASP.NET Core搭建多层网站架构【4-工作单元和仓储设计】
- map的使用-Hdu 2648
- Centos7 虚拟环境安装Django 出现ImproperlyConfigured(&#39;SQLite 3.8.3 or later is required (found %s).&#39; %Database.sqlite_version)错误
- spring 参数校验
- windows 配置hadoop环境
- 201771010135杨蓉庆《面向对象程序设计(java)》第六周学习总结