LintCode: 和大于S的最小子数组
来源:互联网 发布:做淘宝目前什么好做啊 编辑:程序博客网 时间:2024/06/14 05:11
LintCode: 和大于S的最小子数组
一前一后两根指针,当当前数组的和大于s时,移动前面的指针直到和小于s为止,比较当前数组长度与ans的大小。
class Solution: # @param nums: a list of integers # @param s: an integer # @return: an integer representing the minimum size of subarray def minimumSize(self, nums, s): # write your code here i, j= 0, 0 n = len(nums) tmp_sum = 0 ans = n + 1 while j < n: tmp_sum += nums[j] if tmp_sum >= s: while tmp_sum >= s and j >= i: ans = min(ans, j - i + 1) tmp_sum -= nums[i] i += 1 j += 1 return ans if ans <= n else -1
1 0
- LintCode-和大于S的最小子数组
- lintcode-406-和大于S的最小子数组
- LintCode: 和大于S的最小子数组
- LintCode-和大于S的最小子数组
- lintcode(406)和大于S的最小子数组
- LintCode:M-和大于S的最小子数组
- 和大于S的最小子数组-LintCode
- lintcode--和大于s的最小数组
- 和大于S的最小子数组
- [Lintcode]Minimum Size Subarray Sum 和大于S的最小子数组
- lintcode刷题——和大于S的最小子数组
- 题目:和大于S的最小子数组
- 406. 和大于S的最小子数组
- 406.Minimum Size Subarray Sum-和大于S的最小子数组(中等题)
- LintCode--最小子数组
- lintcode ----最小子数组
- LintCode: 最小子数组
- lintcode--最小子数组
- A003-算法-遗传算法-绘图-(ques=1)
- PATB1006:换个格式输出整数
- Codeforces 659C Tanya and Toys
- Oracle和MySQL的区别
- Mybatis-02总结
- LintCode: 和大于S的最小子数组
- PATB1021:个位数统计
- Android之自定义View
- TextView的使用(不定期更新)
- Linux进程间通信——使用消息队列
- PATB1002:写出这个数
- 关于Java值传递和引用传递的总结
- [机器学习]PCA 和协方差矩阵
- TOJ 2829.Cow Counting