{"id":2426,"date":"2022-01-26T19:05:55","date_gmt":"2022-01-26T11:05:55","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2426"},"modified":"2022-01-26T19:05:55","modified_gmt":"2022-01-26T11:05:55","slug":"leetcode90","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/26\/leetcode90\/","title":{"rendered":"leetcode90&#8211;\u5b50\u96c6 II"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c\u5176\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u8bf7\u4f60\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\u8fd4\u56de\u7684\u89e3\u96c6\u4e2d\uff0c\u5b50\u96c6\u53ef\u4ee5\u6309&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u6392\u5217\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,2]\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;&#91;],&#91;1],&#91;1,2],&#91;1,2,2],&#91;2],&#91;2,2]]<\/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>\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=90 lang=python3\r\n#\r\n# &#91;90] \u5b50\u96c6 II\r\n#\r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def subsetsWithDup(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        nums.sort()\r\n        for i in range(len(nums)+1):\r\n            res=combine(len(nums),i)\r\n            for item in res:\r\n\t            if not item in re:\r\n\t\t            re.append(item)\r\n        return re\r\n\r\n\r\n# @lc code=end<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"862\" height=\"268\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-298.png\" alt=\"\" class=\"wp-image-2427\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-298.png 862w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-298-300x93.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-298-768x239.png 768w\" sizes=\"(max-width: 862px) 100vw, 862px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;nums&nbsp;\uff0c\u5176\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u8bf7\u4f60\u8fd4\u56de\u8be5\u6570\u7ec4\u6240\u6709\u53ef\u80fd\u7684\u5b50\u96c6\uff08\u5e42\u96c6\uff09\u3002 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/26\/leetcode90\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcode90&#8211;\u5b50\u96c6 II<\/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\/2426"}],"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=2426"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2426\/revisions"}],"predecessor-version":[{"id":2428,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2426\/revisions\/2428"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2426"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}