3Sum solution with hashing


  • 0
    S

    """
    class Solution(object):
    def threeSum(self, nums):
    """
    :type nums: List[int]
    :rtype: List[List[int]]
    """
    result = []
    for i in range(len(nums)-2):
    track = {}

            for j in range((i+1),len(nums)-1):
                if -(nums[i]+nums[j]) in track:
                    result.append((nums[i],nums[j],-nums[i]+nums[j]))
                    #print((nums[i],nums[j],-nums[i]+nums[j]))
                else:
                    track[nums[j]] = 1
                
        
        return result       
    

    """


Log in to reply
 

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