Simple Python solution


  • 0
    J
    def maxSubArrayLen(self, nums, k):
        rs={}
        sum=0
        maxL=0
        for i in range(len(nums)):
            sum+=nums[i]
            rs[sum]=i
        for i in range(len(nums)):
            j=rs.get(k,None)
            if j != None and j-i+1 > maxL:
                maxL=j-i+1
            k+=nums[i]
        return maxL
    

Log in to reply
 

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