Not bad solution i guess


  • 0
    Q
    class Solution(object):
        def minSubArrayLen(self, s, nums):
            """
            :type s: int
            :type nums: List[int]
            :rtype: int
            """
            left = 0
            right = 0
            cur_sum = 0
            min_len = len(nums) + 1
            for num in nums:
                # Stop this fucking bullshit
                if min_len == 1:
                    return 1
                
                cur_sum += num
                if cur_sum >= s:
                    while cur_sum >= s:
                        cur_sum = cur_sum - nums[left]
                        if cur_sum < s:
                            min_len = min(min_len, right - left + 1)
                        left = left + 1
                right = right + 1
            
            return min_len if  len(nums) + 1 > min_len else 0
    

Log in to reply
 

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