Medium
https://leetcode.com/problems/minimum-size-subarray-sum/
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:
1 |
Input: s = 7, nums = [2,3,1,2,4,3] |
Follow up:
If you have figured out the O(n) solution, try coding another solution of which the time complexity is O(n log n).
方法:
滑动窗口方法,注意判断 min_len 的位置
1 |
class (object): |
类似题目:
Maximum Size Subarray Sum Equals k
Maximum Length of Repeated Subarray
近期评论