Find all combinations of a given set of numbers

前端 未结 9 1643
故里飘歌
故里飘歌 2020-12-03 09:30

say I have a set of numbers \'0\', \'1\', \'2\', ..., \'9\'. I want to find all numbers that contain exactly one of each of the numbers in my set.

The problem is: Be

9条回答
  •  悲&欢浪女
    2020-12-03 09:47

    So, let's say you have the numbers 1, 2 and 3.

    If you are expecting the six numbers 123, 132, 213, 231, 312 and 321 to be the correct answer, what you're looking for is some code to generate all permutations of a set, that'll be faster than almost anything else for problems of an interesting size. You're looking at O(n!) as a best case, though.

提交回复
热议问题