LeetCode 357. それぞれの桁数の異なる数(C、python)を計算する

789 ワード


非負の整数nが与えられ、各数字が異なる数字xの個数が計算され、0≦x<10 nである.
例:
  : 2
  : 91 
  :        11,22,33,44,55,66,77,88,99  ,  [0,100)         。

C
int countNumbersWithUniqueDigits(int n) 
{
    if(n==0)
    {
        return 1;
    }
    int res=10;
    int con=9;
    for(int i=1;i

python
class Solution:
    def countNumbersWithUniqueDigits(self, n):
        """
        :type n: int
        :rtype: int
        """
        if n==0:
            return 1
        res=10
        con=9
        for i in range(1,n):
            res+=con*(10-i)
            con*=(10-i)
        return res