Submission Result: Time Limit Exceeded (I'm wrong?)


  • 0
    H

    class Solution {
    public List<List<Integer>> threeSum(int[] nums) {

            int i,j,k,m,n,t,h; /* rookie~~~ */
            List<List<Integer>> aaa=new ArrayList<List<Integer>>();
    
                        
            for(i=0;i<nums.length-2;i++)
            {
            	for(j=i+1;j<nums.length-1;j++)
            	{
                    for(t=j+1;t<nums.length;t++)
                    {
                        
            		    if(nums[i]+nums[j]+nums[t]==0)
            		    {                                              
                        int p=0;
                        if(aaa.isEmpty())
                        {
            			Integer[] arr = {nums[i],nums[j],nums[t]};       			
            			aaa.add( new ArrayList(Arrays.asList(arr))) ;
                        }
                        else if(!aaa.isEmpty())
                          {
                            Integer[] arr = {nums[i],nums[j],nums[t]};     
                            Arrays.sort(arr);
                            for(n=0;n<aaa.size();n++)
                            { 
                                List<Integer> a = new ArrayList<Integer>();      
                                a=aaa.get(n);
                                
                                Integer[] brr=new Integer[3];
                                for(h=0;h<3;h++)
                                {
                                    brr[h]=a.get(h);
                                }
                                Arrays.sort(brr);
                                if(Arrays.equals(arr,brr))
                                {
                                    p++;
                                }
                            }
                            
                            if(p==0)aaa.add( new ArrayList(Arrays.asList(arr))) ;
                                                       
                        }
            		}	        			      		
            	  }
                }
            }
    
                return aaa;            
        }        
    

    }
    }
    }

                return aaa;
            
        }
    

    }


Log in to reply
 

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