Skip to content

Commit c941078

Browse files
authored
Update 357-count-numbers-with-unique-digits.js
1 parent 3bbdcb8 commit c941078

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

357-count-numbers-with-unique-digits.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
const countNumbersWithUniqueDigits = function(n) {
6+
if(n === 0) return 1
7+
let res = 10
8+
let uniqueDigits = 9, avail = 9
9+
while(n > 1 && avail) {
10+
uniqueDigits = uniqueDigits * avail
11+
res += uniqueDigits
12+
avail--
13+
n--
14+
}
15+
16+
return res
17+
};
18+
19+
// another
20+
121
/**
222
* @param {number} n
323
* @return {number}

0 commit comments

Comments
 (0)