Count Numbers with Unique Digits LeetCode solution in Java

1
class Solution {
2
public int countNumbersWithUniqueDigits(int n) {
3
/*
4
9 * 9 + 10 for n = 2
5
9 * 9 * 8 + 10 for n = 3
6
9 * 9 * 8 * 7 + 10 for n = 4
7
9 * 9 * 8 * 7 * 6 + 10 for n = 5
8
*/
9
if (n == 0) return 1;
10

11
if (n == 1) return 10;
12

13
int product = 9;
14
int result = 10;
15

16
for (int i = 2; i <= n; i++) {
17
product = product * (11 - i);
18
result += product;
19
}
20

21
return result;
22
}
23
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0