No of numbers less than a given number with no repeating digits

后端 未结 3 636
孤独总比滥情好
孤独总比滥情好 2021-01-06 11:11

How can we find the number of numbers less than a given number with no repeating digits in it?

For example the number of such numbers less than 100 is 90. (11, 22, 3

3条回答
  •  萌比男神i
    2021-01-06 11:33

    Here is a way to make it quicker. Notice that there is a correlation between the number of digits in the max number and the solution (number of numbers which I will call NON)

    100 (3 digits) => NON = 10 * 9  
    1000 (4 digits) => NON = 10 * 9 * 8  
    10000 (5 digits) => NON = 10 * 9 * 8 * 7  
    ...  
    10000000000 (11 digits) => NON = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1
    

    after one billion you're bound to repeat a digit

提交回复
热议问题