🟡 剑指 Offer II 008. 和大于等于 target 的最短子数组
LeetCode 提示
题目难度 中等
原题链接 🔗 leetcode
#
题解 1.pyclass Solution: def minSubArrayLen(self, target: int, nums: List[int]) -> int: l, r, m = 0, 0, len(nums)+1 cur = nums[0] right = len(nums)-1
while l <= right and r <= right: if cur < target or l > r: r += 1 if r <= right: cur += nums[r] else: break else: m = min(m, r-l+1) cur -= nums[l] l += 1 return m if m <= len(nums) else 0