{"id":717,"date":"2020-09-26T11:14:02","date_gmt":"2020-09-26T03:14:02","guid":{"rendered":"http:\/\/39.96.58.60\/?p=717"},"modified":"2022-10-18T16:38:15","modified_gmt":"2022-10-18T08:38:15","slug":"leetcode-264-%e4%b8%91%e6%95%b0-ii","status":"publish","type":"post","link":"http:\/\/www.yatenglg.cn\/blog\/?p=717","title":{"rendered":"Leetcode 264. \u4e11\u6570 II"},"content":{"rendered":"<p>\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u627e\u51fa\u7b2c <code>n<\/code> \u4e2a\u4e11\u6570\u3002<\/p>\n<p>\u4e11\u6570\u5c31\u662f\u8d28\u56e0\u6570\u53ea\u5305\u542b&nbsp;<code>2, 3, 5<\/code> \u7684<strong>\u6b63\u6574\u6570<\/strong>\u3002<\/p>\n<p><strong>\u793a\u4f8b:<\/strong><\/p>\n<pre><strong>\u8f93\u5165:<\/strong> n = 10\n\n<strong>\u8f93\u51fa:<\/strong> 12\n\n<strong>\u89e3\u91ca: <\/strong><code>1, 2, 3, 4, 5, 6, 8, 9, 10, 12<\/code> \u662f\u524d 10 \u4e2a\u4e11\u6570\u3002<\/pre>\n<p><strong>\u8bf4\u660e:&nbsp;<\/strong>&nbsp;<\/p>\n<ol>\n<li><code>1<\/code>&nbsp;\u662f\u4e11\u6570\u3002<\/li>\n<li><code>n<\/code>&nbsp;<strong>\u4e0d\u8d85\u8fc7<\/strong>1690\u3002<\/li>\n<\/ol>\n<p>**\u96be\u5ea6**: Medium<\/p>\n<p>**\u6807\u7b7e**: \u5806\u3001 \u6570\u5b66\u3001 \u52a8\u6001\u89c4\u5212\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\uff1a164 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8677.50% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a13.6 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8691.44% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u4e09\u6307\u9488\uff0c\u53c2\u8003\u7684\u5b98\u65b9\u89e3\u9898\u601d\u8def\uff1ahttps:\/\/leetcode-cn.com\/problems\/ugly-number-ii\/solution\/chou-shu-ii-by-leetcode\/\n\"\"\"\nclass Solution:\n    def nthUglyNumber(self, n: int) -&gt; int:\n        p2, p3, p5 = 0, 0, 0\n        dp = [1 for _ in range(n)]\n        for i in range(1, n):\n            min_ = min(2*dp[p2], 3*dp[p3], 5*dp[p5])\n            dp[i] = min_\n            if dp[p2] * 2 == min_:\n                p2 += 1\n            if dp[p3] * 3 == min_:\n                p3 += 1\n            if dp[p5] * 5 == min_:\n                p5 += 1\n        return dp[-1]<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u627e\u51fa\u7b2c n \u4e2a\u4e11\u6570\u3002 \u4e11\u6570\u5c31\u662f\u8d28\u56e0\u6570\u53ea\u5305\u542b&nbsp;2, 3, 5 \u7684\u6b63\u6574\u6570\u3002 \u793a\u4f8b: \u8f93\u5165:&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","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\/717"}],"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=717"}],"version-history":[{"count":1,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/717\/revisions"}],"predecessor-version":[{"id":718,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/717\/revisions\/718"}],"wp:attachment":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=717"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}