Skip to content

Commit 14e4430

Browse files
committed
add description
1 parent a199df0 commit 14e4430

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Math/count_unique_digits,go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
/*
2+
This function takes an integer n as input and returns the count of all positive numbers with unique digits that have n
3+
digits or less. The function first handles the base case where n = 0 (only 1 possible number, 0). For n > 0,
4+
the function initializes the count to 10 (digits 0-9), and then iterates through each number of digits from 2 to n.
5+
For each number of digits, the function calculates the number of possible unique numbers and adds it to the total count.
6+
The number of possible unique numbers for i digits is calculated by first choosing the first digit (9 choices) and then
7+
choosing each subsequent digit (8 choices for the second digit, 7 choices for the third digit, and so on).
8+
The product of all these choices is the total number of possible unique numbers for i digits.
9+
This calculation is repeated for each number of digits from 2 to n, and the total count is returned at the end.
10+
11+
For example, if n = 2, the function should return 91. There are 10 possible numbers with 1 digit (0-9), and
12+
91 possible numbers with 2 digits (10-99) that have unique digits
13+
*/
114
package main
215

316
import (
4-
"fmt"
17+
"fmt"
518
)
619

720
func countNumbersWithUniqueDigits(n int) int {

0 commit comments

Comments
 (0)