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

  • 0

    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>();
            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
            if(num == 0)
            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 ++;
                list.remove(list.size() - 1);// don't store current number and get to the next recursive step
                getSub(res, list, S, num, index);

  • 0

    Your Solution should contain a method subsetsWithDup.

    But yours is named as subsets.

  • 0

    You should change

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


       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.