Python | Leetcode Python题解之第357题统计各位数字都不同的数字个数

题目:

Python | Leetcode Python题解之第357题统计各位数字都不同的数字个数_第1张图片

题解:

class Solution:
    def countNumbersWithUniqueDigits(self, n: int) -> int:
        if n == 0:
            return 1
        if n == 1:
            return 10
        res, cur = 10, 9
        for i in range(n - 1):
            cur *= 9 - i
            res += cur
        return res

你可能感兴趣的:(分享,Python,Leetcode,题解)