zoukankan      html  css  js  c++  java
  • 边工作边刷题:70天一遍leetcode: day 43

    Count Numbers with Unique Digits

    要点:排列组合题,思路是对的,但是实现上出了不少问题

    • 想到了要不同位个数累加。这是因为比如1位,000-009如果按三位计算都是不符合的,但是实际是要累积的。
    • 当时忽略了0不能在最高位。所以把最高位但提出来*9(总共10不包括0),剩下的位就是P(9, x)了(剩下的9个数,包括0)
    • 这种0在开头的情况,一般可以把0本身整合进去,这里pre就变成1,也即0作为0位的唯一情况。
    class Solution(object):
        def countNumbersWithUniqueDigits(self, n):
            """
            :type n: int
            :rtype: int
            """
            if n==0: return 1
            pre = 1 # error 1: start with 1 because 0 means 0 digit case
            for i in xrange(1, n+1):
                if i>10: break
                pre += 9*math.factorial(9)//math.factorial(9-i+1)
                # print pre
            
            return pre
    
  • 相关阅读:
    hadoop yarn日志分离
    hadoop优化
    hive UDF
    hadoophttpfs
    spark编译
    spark feature
    python
    python 装饰器
    HTML特殊转义字符列表
    博客园数据统计
  • 原文地址:https://www.cnblogs.com/absolute/p/5690302.html
Copyright © 2011-2022 走看看