Permutation of String letters: How to remove repeated permutations?

前端 未结 10 2268
遇见更好的自我
遇见更好的自我 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 08:50

    Another approach could be:

    1. Presort the array.

    2. This will ensure that all duplicate are now consecutive.

    3. So, we just need to see the previous element which we we fixed (and permuted others)

    4. if current element is same as previous, don't permute.

提交回复
热议问题