Untitled

mail@pastecode.io avatar
unknown
python
12 days ago
570 B
3
Indexable
Never
class Solution(object):
    def threeSum(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """

        result = []

        for i in range(len(nums)-1):

            target = -nums[i]
            seen = {}

            j = i + 1
            while j < len(nums): 
                third_element = target - nums[j]
                if third_element in seen:
                    result.append([target, nums[j], third_element])
                    j+=1
                seen[nums[j]] = j
                j+=1
        return result 
Leave a Comment