{"id":2388,"date":"2022-01-25T18:51:15","date_gmt":"2022-01-25T10:51:15","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2388"},"modified":"2022-01-25T18:51:16","modified_gmt":"2022-01-25T10:51:16","slug":"leetcodeday78","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/25\/leetcodeday78\/","title":{"rendered":"leetcodeday78 &#8211;\u5b50\u96c6"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c\u6570\u7ec4\u4e2d\u7684\u5143\u7d20&nbsp;<strong>\u4e92\u4e0d\u76f8\u540c<\/strong>&nbsp;\u3002\u8fd4\u56de\u8be5\u6570\u7ec4\u6240\u6709\u53ef\u80fd\u7684\u5b50\u96c6\uff08\u5e42\u96c6\uff09\u3002<\/p>\n\n\n\n<p>\u89e3\u96c6&nbsp;<strong>\u4e0d\u80fd<\/strong>&nbsp;\u5305\u542b\u91cd\u590d\u7684\u5b50\u96c6\u3002\u4f60\u53ef\u4ee5\u6309&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u8fd4\u56de\u89e3\u96c6\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>nums = &#91;1,2,3]\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;&#91;],&#91;1],&#91;2],&#91;1,2],&#91;3],&#91;1,3],&#91;2,3],&#91;1,2,3]]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>nums = &#91;0]\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;&#91;],&#91;0]]<\/code><\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li><code>1 &lt;= nums.length &lt;= 10<\/code><\/li><li><code>-10 &lt;= nums[i] &lt;= 10<\/code><\/li><li><code>nums<\/code>\u00a0\u4e2d\u7684\u6240\u6709\u5143\u7d20\u00a0<strong>\u4e92\u4e0d\u76f8\u540c<\/strong><\/li><\/ul>\n\n\n\n<p>\u601d\u8def\uff1a\u6839\u636e77\u9898\u7684\u89e3\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=78 lang=python3\r\n#\r\n# &#91;78] \u5b50\u96c6\r\n#\r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def subsets(self, nums: List&#91;int]) -> List&#91;List&#91;int]]:\r\n        def combine(n: int, k: int):\r\n            rev=list()\r\n            res=list()\r\n            import copy\r\n            def f(n,k):\r\n                if k==0:\r\n                    re=copy.deepcopy(rev)\r\n                    res.append(re)\r\n                    return \r\n\r\n                else:\r\n                    for i in range(n,k-1,-1):\r\n                        rev.append(nums&#91;i-1])\r\n                        f(i-1,k-1)\r\n                        rev.pop()\r\n            f(n,k)  \r\n            return res\r\n        re=list()\r\n        for i in range(len(nums)+1):\r\n            res=combine(len(nums),i)\r\n            re=res+re\r\n        return re\r\n<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-292.png\" alt=\"\" class=\"wp-image-2390\" width=\"490\" height=\"171\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-292.png 773w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-292-300x105.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-292-768x269.png 768w\" sizes=\"(max-width: 490px) 100vw, 490px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;nums&nbsp;\uff0c\u6570\u7ec4\u4e2d\u7684\u5143\u7d20&nbsp;\u4e92\u4e0d\u76f8\u540c&nbsp;\u3002\u8fd4\u56de\u8be5\u6570\u7ec4\u6240\u6709 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/25\/leetcodeday78\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday78 &#8211;\u5b50\u96c6<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2388"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2388"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2388\/revisions"}],"predecessor-version":[{"id":2391,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2388\/revisions\/2391"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2388"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}