```
public int countNumbersWithUniqueDigits(int n) {
if (n==0) return 1;
n = Math.min(n, 10);
int dp = 10;
int sum = 9;
int pos = 9;
for (int i = 2; i <=n; i++) {
sum = sum * pos--;
dp= dp+sum;
}
return dp;
}
```