Could anyone tell me that why I got Output Limit Exceeded errors? Thanks!


  • 1
    D
        public ArrayList<ArrayList<Integer>> subsets(int[] S) {
        return subsetsHelper1(S, 0);
    }
    
    private ArrayList<ArrayList<Integer>> subsetsHelper1(int[] S, int index) {
        ArrayList<ArrayList<Integer>> allSubsets = new ArrayList<ArrayList<Integer>>();
        int len = S.length;
        if (len == 0)
            return allSubsets;
        
        if (index == len) {
            allSubsets.add(new ArrayList<Integer>());
            return allSubsets;
        } else {
            ArrayList<ArrayList<Integer>> curSubsets = subsetsHelper1(S, index + 1);
            allSubsets.addAll(curSubsets);
            int curVal = S[index];
            for (int i = 0; i < curSubsets.size(); i++) {
                ArrayList<Integer> set = curSubsets.get(i);
                set.add(0, curVal);
            }
            
            allSubsets.addAll(curSubsets);
            return allSubsets;
        }
    }

  • 0
    L

    Because of the line allSubsets.addAll(curSubsets); before the final return . You have already done that previously.


  • 0
    D

    Thanks, I already fixed it.


Log in to reply
 

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