Error msg doesn't make sense


  • 0
    N
    public class Solution {
    public ArrayList<ArrayList<Integer>> permute(int[] num) {
        if (num==null) return null;
        Set<ArrayList<Integer>> existLists = new Set<ArrayList<Integer>>();
        ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
        return permuteHelper(result, existLists, num, 0);
    }
    
    public void permuteHelper(ArrayList<ArrayList<Integer>> result, Set<ArrayList<Integer>> existLists, int[] num, int i) {
        if(i<0) return;
        if(i==num.length) {
            ArrayList<Integer> newList = arrayToArrayList(num);
            if(!existLists.contains(newList)) {
                result.add(newList);
                existLists.add(newList);
                return;
            }
        }
        
        for(int j=i;j<num.length; j++) {
            swap(num, i,j);
            permuteHelper(result, existLists, num, i+1);
            swap(num, i,j);
        }
        return;
    }
    
    public void swap(int[] num, int i, int j) {
        int tmp = num[i];
        num[i]=num[j];
        num[j]=tmp;
    }
    
    public ArrayList<Integer> arrayToArrayList(int[] num) {
        ArrayList<Integer> result = new ArrayList<Integer>();
        for(int i=0; i<num.length; i++) {
            result.add(num[i]);
        }
        return result;    
    }
    

    }

    above is my solution, when submitting to OJ, it has compiler error
    Line 14: error: cannot find symbol: method permuteUnique(int[])
    However, Line14 is: result.add(newList); didn't get where permuteUnique comes from?


  • 2
    V

    I think you need name your function "permuteUnique" to get recognized by OJ, so that OJ knows which function to call and test.


Log in to reply
 

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