private void permuteHelper(int size) {
        if (size == num.length) {
            ArrayList<Integer> list = new ArrayList<Integer>();
            for (int i = 0; i < num.length; i++) {
                list.add(ans[i]);
            }
            result.add(list);
            return;
        }

        for (int i = 0; i < num.length; i++) {
            if (used[i])
                continue;
            if (i > 0 && num[i - 1] == num[i] && !used[i - 1])
                continue;

            used[i] = true;
            ans[size] = num[i];
            permuteHelper(size + 1);
            used[i] = false;
        }
    }