Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def minSubArrayLen(self, target: int, nums: List[int]) -> int:
- cur=0
- ans=pow(10,8)
- k=0
- for i in range(len(nums)):
- cur+=nums[i]
- while cur>=target:
- ans=min(i-k+1,ans) #doing comparison everytime will reduce the size and won't impact the answer also.
- cur-=nums[k]
- k+=1
- return ans if ans!=pow(10,8) else 0
Advertisement
Add Comment
Please, Sign In to add comment