@Test public void countNumbersWithUniqueDigits() { assertEquals(91, CountNumbersUniqueDigitsSolution.countNumbersWithUniqueDigits(2)); }
static int countNumbersWithUniqueDigits(int n) { if (n == 0) return 1; int res = 10; int uniqueDigits = 9; int availableNumber = 9; while (n-- > 1 && availableNumber > 0) { uniqueDigits = uniqueDigits * availableNumber; res += uniqueDigits; availableNumber--; } return res; }
CountNumbersUniqueDigitsSolution { static int countNumbersWithUniqueDigits(int n) { if (n == 0) return 1; int res = 10; int uniqueDigits = 9; int availableNumber = 9; while (n-- > 1 && availableNumber > 0) { uniqueDigits = uniqueDigits * availableNumber; res += uniqueDigits; availableNumber--; } return res; } }
CountNumbersUniqueDigitsSolution { static int countNumbersWithUniqueDigits(int n) { if (n == 0) return 1; int res = 10; int uniqueDigits = 9; int availableNumber = 9; while (n-- > 1 && availableNumber > 0) { uniqueDigits = uniqueDigits * availableNumber; res += uniqueDigits; availableNumber--; } return res; }  }
CountNumbersUniqueDigitsSolution { static int countNumbersWithUniqueDigits(int n) { if (n == 0) return 1; int res = 10; int uniqueDigits = 9; int availableNumber = 9; while (n-- > 1 && availableNumber > 0) { uniqueDigits = uniqueDigits * availableNumber; res += uniqueDigits; availableNumber--; } return res; }   }
CountNumbersUniqueDigitsSolution { static int countNumbersWithUniqueDigits(int n) { if (n == 0) return 1; int res = 10; int uniqueDigits = 9; int availableNumber = 9; while (n-- > 1 && availableNumber > 0) { uniqueDigits = uniqueDigits * availableNumber; res += uniqueDigits; availableNumber--; } return res; }    }