分析
用排列的方法统计每位数数字不同的个数
然后累加起来即可
ac code
class Solution:
def countNumbersWithUniqueDigits(self, n: int) -> int:
if n == 0:
return 1
temp = list(range(9, 0, -1))
temp.insert(0, 9)
print(temp)
ans = 1
res = [1]
front = 1
for i in range(n):
ans *= temp[i]
front += ans
return front
总结
简单累加判断组合