public int countNumbersWithUniqueDigits(int n) {
int totalCount = 1;
for(int i = 1; i <= n; i++)
{
int j = i, digit = 9, count = 1;
while(j > 1) { count *= digit; }
totalCount += 9*count;
}
return totalCount;
}
0ms 10line Java solution in O(1) space (Nobacktrack noDP)

@ros62 This is very elegant. Basically you count all possible n digits and all possible n1 digits and all possible n2 digits number. I really like it.