Find all combinations of a given set of numbers

前端 未结 9 1647
故里飘歌
故里飘歌 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:48

    Nothing to do with dynamic programming; unless you want to wear underpants outside your trousers and paint a symbol on your chest.

    Simple way to do it is maintain an array of 0-9 of integers, then run through the numbers one by one and increment array[num]. The result, once you've processed all digits, is to see if any element of the array is non-zero or one. (That indicates a repeated digit.) Of course, it's trivial to take a number and then iterate through digit by digit using modulus and divisor.

提交回复
热议问题