{"id":387,"date":"2020-09-26T10:35:31","date_gmt":"2020-09-26T02:35:31","guid":{"rendered":"http:\/\/39.96.58.60\/?p=387"},"modified":"2022-10-18T16:39:35","modified_gmt":"2022-10-18T08:39:35","slug":"leetcode-357-%e8%ae%a1%e7%ae%97%e5%90%84%e4%b8%aa%e4%bd%8d%e6%95%b0%e4%b8%8d%e5%90%8c%e7%9a%84%e6%95%b0%e5%ad%97%e4%b8%aa%e6%95%b0","status":"publish","type":"post","link":"http:\/\/www.yatenglg.cn\/blog\/?p=387","title":{"rendered":"Leetcode 357. \u8ba1\u7b97\u5404\u4e2a\u4f4d\u6570\u4e0d\u540c\u7684\u6570\u5b57\u4e2a\u6570"},"content":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a<strong>\u975e\u8d1f<\/strong>\u6574\u6570 n\uff0c\u8ba1\u7b97\u5404\u4f4d\u6570\u5b57\u90fd\u4e0d\u540c\u7684\u6570\u5b57 x \u7684\u4e2a\u6570\uff0c\u5176\u4e2d 0 \u2264 x &lt; 10<sup>n&nbsp;<\/sup>\u3002<\/p>\n<p><strong>\u793a\u4f8b:<\/strong><\/p>\n<pre><strong>\u8f93\u5165: <\/strong>2\n\n<strong>\u8f93\u51fa: <\/strong>91 \n\n<strong>\u89e3\u91ca: <\/strong>\u7b54\u6848\u5e94\u4e3a\u9664\u53bb <code>11,22,33,44,55,66,77,88,99 <\/code>\u5916\uff0c\u5728 [0,100) \u533a\u95f4\u5185\u7684\u6240\u6709\u6570\u5b57\u3002\n\n<\/pre>\n<p>**\u96be\u5ea6**: Medium<\/p>\n<p>**\u6807\u7b7e**: \u6570\u5b66\u3001 \u52a8\u6001\u89c4\u5212\u3001 \u56de\u6eaf\u7b97\u6cd5\u3001<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-python\" data-lang=\"Python\"><code>\n# -*- coding: utf-8 -*-\n# @Author  : LG\n\n\"\"\"\n\u6267\u884c\u7528\u65f6\uff1a36 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8685.03% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a13.5 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8693.39% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u52a8\u6001\u89c4\u5212\n        0 &lt;= x &lt; 10**n, x\u4e3a\u6700\u5927n\u4f4d\u6570\n        m       num             \u8bf4\u660e\n        1\u4f4d\u6570     10          0,1~9\n        2\u4f4d\u6570     9*9         \u7b2c\u4e00\u4f4d9\u4e2a\uff1a1~9 \u7b2c\u4e8c\u4f4d10-1\u4e2a\uff1a0~9\n        3\u4f4d\u6570     9*9*8       \u7b2c\u4e00\u4f4d9\u4e2a\uff1a1~9 \u7b2c\u4e8c\u4f4d10-1\u4e2a\uff1a0~9 \u7b2c\u4e09\u4f4d10-2\u4e2a0~9\n        4\u4f4d\u6570     9*9*8*7     \u7b2c\u4e00\u4f4d9\u4e2a\uff1a1~9 \u7b2c\u4e8c\u4f4d10-1\u4e2a\uff1a0~9 \u7b2c\u4e09\u4f4d10-2\u4e2a0~9 \u7b2c\u56db\u4f4d10-3\u4e2a0~9\n        5\u4f4d\u6570     9*9*8*7*6\n        6\u4f4d\u6570     9*9*8*7*6*5\n        7\u4f4d\u6570     9*9*8*7*6*5*4\n        8\u4f4d\u6570     9*9*8*7*6*5*4*3\n        9\u4f4d\u6570     9*9*8*7*6*5*4*3*2\n        10\u4f4d\u6570    9*9*8*7*6*5*4*3*2*1\n\"\"\"\nclass Solution:\n    def countNumbersWithUniqueDigits(self, n: int) -&gt; int:\n        dp = [0 for _ in range(10)]\n        dp[:3] = [1, 9, 81]\n        for i in range(3,10):\n            dp[i] = dp[i-1]*(10-i+1)\n        if n &gt; 9:\n            n = 9\n        return sum(dp[:n+1])<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 n\uff0c\u8ba1\u7b97\u5404\u4f4d\u6570\u5b57\u90fd\u4e0d\u540c\u7684\u6570\u5b57 x \u7684\u4e2a\u6570\uff0c\u5176\u4e2d 0 \u2264 x &lt; 10n&nbsp;\u3002 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/387"}],"collection":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=387"}],"version-history":[{"count":1,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/387\/revisions"}],"predecessor-version":[{"id":388,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/387\/revisions\/388"}],"wp:attachment":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=387"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}