public void dfs(ArrayList<Integer> nums, int begin) {
        if (begin >= nums.size()) {
            res.add(new ArrayList<Integer>(nums));
            return;
        }
        HashSet<Integer> set = new HashSet<Integer>();
        for (int i = begin; i < nums.size(); ++i) {
            int val = nums.get(i);
            if (set.contains(val))
                continue;
            set.add(val);
            swap(nums, begin, i);
            dfs(nums, begin + 1);
            swap(nums, begin, i);
        }
    }