Permutation of String letters: How to remove repeated permutations?

前端 未结 10 2282
遇见更好的自我
遇见更好的自我 2020-12-25 08:39

Here is a standard function to print the permutations of characters of a string:

void permute(char *a, int i, int n)
{
   int j;
   if (i == n)
     printf(\         


        
10条回答
  •  别那么骄傲
    2020-12-25 09:09

    You can use std::set to ensure uniqueness of the results. That is if it is C++ (because you tagged it as such).

    Otherwise - go through the list of the results manually and remove duplicates.

    You'll have to save the results and post-process them of course, not print immediately as you do now.

提交回复
热议问题