Maximum Size Subarray Sum Equals k

class Solution(object):
    def maxSubArrayLen(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """

        hashmap = {}
        hashmap[0] = -1
        sum = 0
        maxlen = 0

        for i in range(len(nums)):
            sum += nums[i]

            if sum - k in hashmap:
                maxlen = max(maxlen, i - hashmap[sum-k])


            if sum not in hashmap:
                hashmap[sum] = i

        return maxlen

results matching ""

    No results matching ""