Skip to content

Commit 148c85c

Browse files
committed
src/bin/count-numbers-with-unique-digits.rs
1 parent d9cb362 commit 148c85c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
fn main() {
2+
println!("{}", Solution::count_numbers_with_unique_digits(2));
3+
println!("{}", Solution::count_numbers_with_unique_digits(8));
4+
println!("{}", Solution::count_numbers_with_unique_digits(7));
5+
}
6+
7+
struct Solution;
8+
9+
impl Solution {
10+
pub fn count_numbers_with_unique_digits(n: i32) -> i32 {
11+
if n == 0 {
12+
return 1;
13+
}
14+
15+
if n == 1 {
16+
return 10;
17+
}
18+
19+
let mut sum =9;
20+
21+
for i in 0..n - 1 {
22+
sum *= 9 - i;
23+
}
24+
25+
sum + Self::count_numbers_with_unique_digits(n - 1)
26+
}
27+
}

0 commit comments

Comments
 (0)