Python Two Pointers


  • 0
    class Solution(object):
        def minSubArrayLen(self, s, nums):
            left, right, sumofary, ans = 0, 0, 0, 0xffffffff
            while right < len(nums):
                while right < len(nums) and sumofary < s:
                    sumofary += nums[right]
                    right += 1
                while left < right and sumofary >= s:
                    ans = min(ans, right - left)
                    sumofary -= nums[left]
                    left += 1
            return ans if ans != 0xffffffff else 0
    

Log in to reply
 

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