点击打开链接
//f(1) = 10, ..., f(k) = 9 * 9 * 8 * ... (9 - k + 2) [The first factor is 9 because a number cannot start with 0]
//各个数字不相同
class Solution {
public:
int countNumbersWithUniqueDigits(int n) {
if(n==0) return 1;
int res = 10;
int base = 9;
for(int i=2;i<=n&&i<=10;i++){
base = base*(9-i+2);
res += base;
}
return res;
}
};