Skip to content

Commit d413c53

Browse files
authored
Update 357-count-numbers-with-unique-digits.js
1 parent 725d1b1 commit d413c53

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
@@ -40,3 +40,23 @@ const countNumbersWithUniqueDigits = function(n) {
4040
return n === 0 ? 1 : helper(m, n - 1) * (m - n + 1)
4141
}
4242
};
43+
44+
// another
45+
46+
/**
47+
* @param {number} n
48+
* @return {number}
49+
*/
50+
const countNumbersWithUniqueDigits = function(n) {
51+
if(n === 0) return 1
52+
let res = 10
53+
let tmp = 9, digits = 9
54+
while(n > 1 && digits > 0) {
55+
tmp *= digits
56+
res += tmp
57+
n--
58+
digits--
59+
}
60+
61+
return res
62+
};

0 commit comments

Comments
 (0)