{"id":449,"date":"2020-09-26T10:43:03","date_gmt":"2020-09-26T02:43:03","guid":{"rendered":"http:\/\/39.96.58.60\/?p=449"},"modified":"2022-10-18T16:39:14","modified_gmt":"2022-10-18T08:39:14","slug":"leetcode-491-%e9%80%92%e5%a2%9e%e5%ad%90%e5%ba%8f%e5%88%97","status":"publish","type":"post","link":"http:\/\/www.yatenglg.cn\/blog\/?p=449","title":{"rendered":"Leetcode 491. \u9012\u589e\u5b50\u5e8f\u5217"},"content":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u578b\u6570\u7ec4, \u4f60\u7684\u4efb\u52a1\u662f\u627e\u5230\u6240\u6709\u8be5\u6570\u7ec4\u7684\u9012\u589e\u5b50\u5e8f\u5217\uff0c\u9012\u589e\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u81f3\u5c11\u662f2\u3002<\/p>\n<p><strong>\u793a\u4f8b:<\/strong><\/p>\n<pre><strong>\u8f93\u5165:<\/strong> [4, 6, 7, 7]\n\n<strong>\u8f93\u51fa:<\/strong> [[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7,7], [4,7,7]]<\/pre>\n<p><strong>\u8bf4\u660e:<\/strong><\/p>\n<ol>\n<li>\u7ed9\u5b9a\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc715\u3002<\/li>\n<li>\u6570\u7ec4\u4e2d\u7684\u6574\u6570\u8303\u56f4\u662f&nbsp;[-100,100]\u3002<\/li>\n<li>\u7ed9\u5b9a\u6570\u7ec4\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u6570\u5b57\uff0c\u76f8\u7b49\u7684\u6570\u5b57\u5e94\u8be5\u88ab\u89c6\u4e3a\u9012\u589e\u7684\u4e00\u79cd\u60c5\u51b5\u3002<\/li>\n<\/ol>\n<p>**\u96be\u5ea6**: Medium<\/p>\n<p>**\u6807\u7b7e**: \u6df1\u5ea6\u4f18\u5148\u641c\u7d22\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\uff1a6804 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8625.89% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a21.3 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8632.02% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u8be6\u89c1\u4ee3\u7801\u6ce8\u91ca\n\"\"\"\nclass Solution:\n    def findSubsequences(self, nums: List[int]) -&gt; List[List[int]]:\n        results = []        # \u7528\u4e8e\u4fdd\u5b58\u6700\u7ec8\u7ed3\u679c\n        for num in nums:    # \u4ee5\u6bcf\u4e2a\u6570\u5b57\u4f5c\u4e3a\u8d77\u59cb\uff0c\u5f00\u59cb\u679a\u4e3e\u6240\u6709\u7ec4\u5408\n            results_ = []   # \u7528\u4e8e\u4fdd\u5b58\u4e2d\u95f4\u7ed3\u679c\uff0c\u8fd9\u91cc\u9700\u8981\u6700\u540e\u66f4\u65b0\u6700\u7ec8\u5217\u8868\uff0c\u6240\u4ee5\u5728\u8ba1\u7b97\u8fc7\u7a0b\u4e2d\u9700\u8981\u4fdd\u5b58\u4e00\u4e2a\u4e2d\u95f4\u503c\n            for result in results:  # \u4ece\u4fdd\u5b58\u7684\u7ed3\u679c\u4e2d\uff0c\u8bfb\u53d6\u5df2\u7ecf\u679a\u4e3e\u8fc7\u7684\u7ed3\u679c\n                if num &gt;= result[-1]:   # \u5f53\u524d\u6570\u5b57\u5927\u4e8e \u7ed3\u679c\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\uff0c\u4e5f\u5c31\u662f\u6700\u5927\u503c\n                    record = result.copy()  # \u56e0\u4e3a\u662f\u5217\u8868\uff0c\u6240\u4ee5\u9700\u8981\u4f7f\u7528copy\n                    record.append(num)      # \u5c06\u5f53\u524d\u6570\u7ec4\u4e0e\u7ed3\u679c \u7ec4\u6210\u65b0\u7684\u4e0a\u5347\u5b50\u5e8f\u5217\n                    if record not in results and record not in results_:    # \u5224\u65ad\u91cd\u590d\n                        results_.append(record)\n            results.extend(results_)    # \u6dfb\u52a0\u7ed3\u679c\n            results.append([num])       # \u9700\u8981\u5c06\u5f53\u524d\u6570\u5b57\u6dfb\u52a0\u5230\u7ed3\u679c\u4e2d\uff0c\u8fd9\u91cc\u662f\u56e0\u4e3a\uff0c\u521d\u59cb\u7ed3\u679c\u662f[]\u7684\uff0c\u6bcf\u6b21\u6bd4\u8f83\u9700\u8981\u4e00\u4e2a\u6700\u521d\u7684\u6bd4\u8f83\u5bf9\u8c61\n        results = [result for result in results if len(result) &gt; 1] # \u7531\u4e8e\u5c06\u5355\u4e2a\u6570\u5b57\u4e5f\u6dfb\u52a0\u8fdb\u4e86\u7ed3\u679c\u4e2d\uff0c\u6240\u4ee5\u9700\u8981\u53bb\u6389\n        return results\n\n\n\"\"\"\n\u6267\u884c\u7528\u65f6\uff1a60 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8699.29% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a19.1 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8699.51% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u5bf9\u4e0a\u4f8b\u8fdb\u884c\u4f18\u5316\u3002\n    \u5c06\u4e0a\u4f8b\u4e2d\u5217\u8868\u64cd\u4f5c\uff0c\u66f4\u6362\u4e3a\u96c6\u5408\uff0c\u7701\u53bb\u4e86\u53bb\u91cd\u6b65\u9aa4\u3002\n\"\"\"\nclass Solution:\n    def findSubsequences(self, nums: List[int]) -&gt; List[List[int]]:\n        results = set()\n        for num in nums:\n            for result in list(results):\n                if num &gt;= result[-1]:\n                    record = result + (num, )\n                    results.add(record)\n            results.add((num, ))\n        results = [result for result in results if len(result) &gt; 1]\n        return results<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u578b\u6570\u7ec4, \u4f60\u7684\u4efb\u52a1\u662f\u627e\u5230\u6240\u6709\u8be5\u6570\u7ec4\u7684\u9012\u589e\u5b50\u5e8f\u5217\uff0c\u9012\u589e\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u81f3\u5c11\u662f2\u3002 \u793a\u4f8b: \u8f93\u5165: [4, &#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\/449"}],"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=449"}],"version-history":[{"count":1,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/449\/revisions"}],"predecessor-version":[{"id":450,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/449\/revisions\/450"}],"wp:attachment":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}