```
public class Solution {
public int countNumbersWithUniqueDigits(int n) {
int a = 1, b = 1, limit = Math.min(n, 10), sum=0;
for (int i=2; i<=limit; i++) {
a*=10;
b*=(10-i+1);
sum+=9 * (a-b);
}
return (int)(Math.pow(10, limit) - sum);
}
}
```