Skip to content

Commit 5b217b8

Browse files
Sean PrashadSean Prashad
authored andcommitted
Add 357_Count_Numbers_with_Unique_Digits.java
1 parent d8ead90 commit 5b217b8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int countNumbersWithUniqueDigits(int n) {
3+
if (n == 0) {
4+
return 1;
5+
}
6+
7+
int result = 10, base = 9;
8+
9+
for (int i = 2; i <= n && i <= 10; i++) {
10+
base = base * (9 - i + 2);
11+
result += base;
12+
}
13+
14+
return result;
15+
}
16+
}

0 commit comments

Comments
 (0)