```
class Solution {
public:
int countNumbersWithUniqueDigits(int n) {
if(n == 0) return 1;
int count = 9, ret = 9;
// In each iteration, try adding 0 - 9 to the end of number
for(int i = 2; i <= n; ++i) {
// Advoid repeating digits. f(k) = f(k - 1) * (10 - k - 1)
count *= 11 - i;
ret += count;
}
// Add 0
return ret + 1;
}
};
```