Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.
Example:
Input: 2 Output: 91 Explanation: The answer should be the total numbers in the range of 0 ≤ x < 100, excluding11,22,33,44,55,66,77,88,99
class Solution(object): def countNumbersWithUniqueDigits(self, n): """ :type n: int :rtype: int """ if n == 0: return 1 if n == 1: return 10 dp = [0] * (n+1) dp[0] = 1 dp[1] = 9 sum = dp[0] + dp[1] for i in range(2, n+1): dp[i] = dp[i-1]*(10-i+1) sum += dp[i] return sum