0
点赞
收藏
分享

微信扫一扫

leetcode:357. 统计各位数字都不同的数字个数【简单模拟】

mm_tang 2022-04-13 阅读 70
python

在这里插入图片描述

分析

用排列的方法统计每位数数字不同的个数
然后累加起来即可

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

总结

简单累加判断组合

举报

相关推荐

0 条评论