help check if this code is right ??thanke you !!! python


  • 0
    S

    '''

     def threeSum(self, nums):  
        l=[]
        
        n=len(nums)
        if n>3:
         for i in range(n-2):
            j=i+1
            while(j<=n-2):
                f=j+1
                while(f<=n-1):
                  if nums[i]+nums[j]+nums[f]==0:
                    l.append([nums[i],nums[j],nums[f]])
                  f=f+1
                j=j+1
         for i in range(len(l)):
            l[i].sort()
         r=[]
         for i in range(len(l)):
            if l[i] not in r:
                
                r.append(l[i])
                
         return r
        if n==3:
            if nums[0]+nums[1]+nums[2]==0:
                 l.append([nums[0],nums[1],nums[2]])
             
                 l[0].sort()
            return l
        if n<3:
            return l
    

    '''

    Submission Result: Time Limit Exceeded


Log in to reply
 

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