时间: 2020-11-24|62次围观|0 条评论

Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.

Example:
Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99])

Credits:
Special thanks to @memoryless for adding this problem and creating all test cases.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 class Solution:      def countNumbersWithUniqueDigits( self , n):          """          :type n: int          :rtype: int          """          used = [ False for x in range ( 10 )]            def gen(used, n, d):              if n = = d:                  return 1              total = 1              startIndex = 1 if d = = 0 else 0              for i in range (startIndex, 10 ):                  if not used[i]:                      used[i] = True                      total + = gen(used, n, d + 1 )                      used[i] = False              return total            return gen(used, n, 0 )     s = Solution() a = s.countNumbersWithUniqueDigits( 7 ) print (a)

来自为知笔记(Wiz)

转载于:https://www.cnblogs.com/xiejunzhao/p/8445742.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/96415695

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《357. Count Numbers with Unique Digits 用唯一的数字计算数字
   

还没有人抢沙发呢~