Using HashSet returns runtime error


  • 0
    L

    My solution using HashSet returns runtime error, why?

    It can pass some classical tests in Eclipse.

    Thx

    public HashSet<List<Integer>> subsetsWithDup(int[] num) {
        HashSet<List<Integer>> ans = new HashSet<List<Integer>>();
        if(num == null) return ans;
        Arrays.sort(num);
        dfs(num, 0, new LinkedList<Integer>(), ans);
        return ans;
    }
    private void dfs(int[] num, int index, LinkedList<Integer> list, HashSet<List<Integer>> ans){
        ans.add(new LinkedList<Integer>(list));
        for(int i = index; i < num.length; i++){
            list.add(num[i]);
            dfs(num, i + 1, list, ans);
            list.remove(list.size() - 1);
        }
    }

Log in to reply
 

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