generating Variations without repetitions / Permutations in java

后端 未结 10 967
半阙折子戏
半阙折子戏 2021-01-02 07:33

I have to generate all variations without repetitions made of digits 0 - 9.

Length of them could be from 1 to 10. I really don\'t know how to solve it, especially ho

10条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 08:11

    Imagine you had a magical function - given an array of digits, it will return you the correct permutations.

    How can you use that function to produce a new list of permutations with just one extra digit?

    e.g.,

    if i gave you a function called permute_three(char[3] digits), and i tell you that it only works for digits 0, 1, 2, how can you write a function that can permute 0, 1, 2, 3, using the given permute_three function?

    ...

    once you solved that, what do you notice? can you generalize it?

提交回复
热议问题