public void dfs(int[] nums, List<Integer> path, HashSet<Integer> visited) {
        if (path.size() == nums.length) {
            ans.add(new ArrayList<Integer>(path));
            return;
        }
        for (int i = 0; i < nums.length; ++i) {
            if (visited.contains(nums[i]))
                continue;
            visited.add(nums[i]);
            path.add(nums[i]);
            dfs(nums, path, visited);
            path.remove(path.size() - 1);
            visited.remove(nums[i]);
        }
    }