Line 15 error: cannot find symbol: method permuteUnique(int[]) ? Test code error?


  • 0
    S

    Test code Error?

    I tried server solutions, first time I use add hash set based on my AC permutations solution, I got this Compile Error. Then I submit the following no-hash-based-code which is tested on my own laptop. I got the same Compile error. Even also in line 15. Here is my no-hash-based-code:

    import java.util.*;
    public class Solution {
        public List<List<Integer>> permute(int[] nums) {
        	List<List<Integer>> list=new ArrayList<List<Integer>>();
        	if(nums.length==1){
        		List<Integer> tmp=new ArrayList<Integer>();
        		tmp.add(nums[0]);
        		list.add(tmp);
        		return list;
        	} 
        	for(int i=0;i<nums.length;i++){
        		int head=nums[i];
        		int[] pool=new int[nums.length-1];
        		int p=0;
        		for(int j=0;j<nums.length;j++)
        			if(i!=j) pool[p++]=nums[j];		
        		List<List<Integer>> tails=permute(pool);
        		int size=tails.size();   		
        		for(int j=0;j<size;j++){
        			List<Integer> sub=new ArrayList<Integer>();
        			sub.add(head);
        			sub.addAll(tails.get(j));
        			if(list.size()==0||smallerThan(list.get(list.size()-1),sub)) 
        			list.add(sub);
        		}   		
        	}
        	return list;
        }
    
        // if first > second
        public boolean smallerThan(List<Integer> first, List<Integer> second){
        	int f=0,s=0;
        	int len=first.size();
        	for(int i=0;i<len;i++){
        		f=10*f+first.get(i);
        		s=10*s+second.get(i);
        	}
        	//System.out.println("f:"+f+" s:"+s);
        	return f<s;
        }
    }
    

    Then I copy an AC solution from Discuss and I got TLE. Why??


  • 0

    The line number probably refers to judge code, so it's misleading, but... do listen to the rest of the error message. You're missing the method permuteUnique. Yours is called permute.

    Without knowing which AC solution you copied, I can only guess that they added larger test cases after that one was accepted.


  • 0
    S

    Thank you.~.


Log in to reply
 

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