LeetCode知识点总结 - 357
LeetCode 357. Count Numbers with Unique Digits
·
LeetCode 357. Count Numbers with Unique Digits
考点 | 难度 |
---|---|
DP | Medium |
题目
Given an integer n
, return the count of all numbers with unique digits, x, where 0 <= x < 10^n.
思路
第一个数字有9个选择,第二个有9个,第三个有8个,etc
答案
class Solution(object):
def countNumbersWithUniqueDigits(self, n):
choices = [9, 9, 8, 7, 6, 5, 4, 3, 2, 1]
ans, product = 1, 1
for i in range(n if n <= 10 else 10):
product *= choices[i]
ans += product
return ans
更多推荐
所有评论(0)