What does this error mean? I don't know how to correct it.


  • 0
    K

    Line 15: error: cannot find symbol: method subsetsWithDup(int[])

    public class Solution {
        public List<List<Integer>> subsets(int[] S) {
            List<List<Integer>> res = new ArrayList<List<Integer>>();
            List<Integer> list = new ArrayList<Integer>();
            Arrays.sort(S);
            
            for(int i = 0; i <= S.length; i ++){
                getSub(res, list, S, i, 0);
            }
            
            return res;
        }
        
        public void getSub(List<List<Integer>> res, List<Integer> list, int[] S, int num, int index){
            if(index == S.length + 1)// will not store this branch
                return;
            if(num == 0)
                res.add(list);
            if(num > 0 && index < S.length){
                list.add(S[index]);// store current number and get to the next recursive step, the number that is still needed counts down
                getSub(res, new ArrayList(list), S, num - 1, index + 1);
                
                int tmp = S[index];
                index ++;
                while(index < S.length){
                    if(tmp == S[index])
                        index ++;
                    else
                        break;
                }
                list.remove(list.size() - 1);// don't store current number and get to the next recursive step
                getSub(res, list, S, num, index);
            }
        }
    }

  • 0
    T

    Your Solution should contain a method subsetsWithDup.

    But yours is named as subsets.


  • 0
    H

    You should change

       public List<List<Integer>> subsets(int[] nums) {
    

    to

       public List<List<Integer>> subsetsWithDup(int[] nums) {
    

    The same problem happened to me, I think it's because I was trying to make changes based on the problem subsets, and copied/pasted the code from that problem and forgot to change the function name. You are probably making the same mistake.

    Very implicit error hint though


Log in to reply
 

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