class Solution:
"""
@param nums: an array
@param k: a target value
@return: the maximum length of a subarray that sums to k
"""
def maxSubArrayLen(self, nums, k):
# Write your code here
presum = 0
dict = {0:-1}
ret = 0
for i, num in enumerate(nums):
presum += num
if presum not in dict:
dict[presum] = i
if presum - k in dict:
ret = max(i - dict[presum - k],ret)
return ret