Permutations II ,why my code has a problem??


  • 0
    public class Solution {
      public static List<List<Integer>> permute(int[] nums) {
    		List<List<Integer>> result=new ArrayList<List<Integer>>();
    		permute(nums,0,result);
    		Set<List<Integer>> set=new HashSet<>(result);
    		return new ArrayList<List<Integer>>(set);
    	}
    	private static void permute(int[] nums, int i, List<List<Integer>> result) {
    		if (i>=nums.length)
    		{
    			ArrayList<Integer> tem=new ArrayList<>();
    			for (int j=0; j<nums.length; j++)
    			{
    				tem.add(nums[j]);
    			}
    			result.add(tem);
    			return;
    		}
    		for (int j=i; j<nums.length; j++)
    		{
    			swap(j,i,nums);
    			permute(nums,i+1,result);   //there is a problem
    			swap(j,i,nums);
    		}
    	}
    	private static void swap(int j, int i, int[] nums) {
    		int tem=nums[i];
    		nums[i]=nums[j];
    		nums[j]=tem;
    	}
    }
    

    there is a compile error:Line 23: error: cannot find symbol: method permuteUnique(int[])
    i have run my code on Eclipse,there is no problem.......?????


  • 0
    Q

    The method name of "Permutations II" is "permuteUnique". You cannot change it. Maybe you just copy codes from "Permutations I" without changing the method name.


Log in to reply
 

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