public ArrayList<ArrayList<Integer>> permuteUnique(int[] num) {
            Arrays.sort(num);
            ArrayList<ArrayList<Integer>> ans = new ArrayList<ArrayList<Integer>>();
            do {
                ArrayList<Integer> l = new ArrayList<Integer>();
                for (int n : num) {
                    l.add(n);
                }
                ans.add(l);
            } while (nextPermutation(num));
            return ans;
        }