This is my code which got an LTE,help me find the problem


  • 0
    H

    public class Solution {
    public List<List<Integer>> permuteUnique(int[] nums) {
    List<List<Integer>> res = new ArrayList<List<Integer>>() ;
    if(nums==null||nums.length==0){
    return null ;
    }

    	 else
    	 {
    		 	return  permute(nums,0,nums.length-1) ;
    	 }
    
    }
    private List<List<Integer>> permute(int[] nums, int i, int j) {
    	 ArrayList<List<Integer>> res = new ArrayList<List<Integer>>() ;
    	 ArrayList<Integer> l = new ArrayList<Integer>() ;
    	if(i==j){
    		l.add(nums[i]);
    		res.add(l);
    		return res ;
    	}
    	int first = nums[i];
    	List<List<Integer>> temp = permute(nums,i+1,j) ;
    	for(List<Integer> al : temp){
    		for(int k = 0 ; k<=al.size() ;k++){
    			List<Integer> new_l = new ArrayList<Integer>(al);
                new_l.add(k,first);
                if(!res.contains(new_l)){
                	res.add(new_l) ;
    			}
                }
    			
    	}
    	return res ;
    }
    

    }


Log in to reply
 

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