1 public class Solution { 2 public int countNumbersWithUniqueDigits(int n) { 3 if (n == 0) { 4 return 1; 5 } 6 int result = 10; 7 int currentD = 9; 8 int nextD = 9; 9 10 while (n-- > 1) { 11 result += currentD * nextD; 12 currentD *= nextD--; 13 } 14 return result; 15 } 16 }
1. When n == 0, it return 1.
2. Since already make result = 10, count until 2.