Time Limit Exceeded (Python)


  • 0
    J

    I am wondering if there are any thing wrong with the code.
    class Solution(object):

        def threeSum(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            nums = sorted(nums)
            com = list(itertools.combinations(nums,3))
            a = []
            for i in range(len(com)):
                if sum(com[i]) == 0:
                    a.append(com[i])
            sorteda = list(set([tuple(sorted(tuple_)) for tuple_ in a]))
            final = [list(i) for i in sorteda]
            return(sorted(final))
    

Log in to reply
 

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