Python AC solution in 40 ms


  • 0
    Z
    class Solution(object):
        def minSubArrayLen(self, s, nums):
            """
            :type s: int
            :type nums: List[int]
            :rtype: int
            """
            if sum(nums) < s or not nums:
                return 0
                
            start = 0
            end = 0
            L = len(nums)
            SUM = 0
            res = L
            
            while SUM <= s and end < L:
                SUM+=nums[end]
                end+=1 
                while SUM>=s and start<end:
                    SUM-=nums[start]
                    start+=1
                    if end-start+1 < res:
                        res = end-start+1
                
            return res

  • 0
    W

    If the list is : [2,5,7,6,3,10] s=10
    According your method, the result is 2, but actually, it should be 1


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.