solution.json 2.2 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "79def0a76b1546459f90832b72be77f8",
  "keywords": "位运算,数组,回溯",
  "title": "子集 II",
  "desc": [
    {
      "content": "\n<p>给你一个整数数组 <code>nums</code> ,其中可能包含重复元素,请你返回该数组所有可能的子集(幂集)。</p><p>解集 <strong>不能</strong> 包含重复的子集。返回的解集中,子集可以按 <strong>任意顺序</strong> 排列。</p><div class=\"original__bRMd\"><div><p> </p><p><strong>示例 1:</strong></p><pre><strong>输入:</strong>nums = [1,2,2]<strong><br />输出:</strong>[[],[1],[1,2],[1,2,2],[2],[2,2]]</pre><p><strong>示例 2:</strong></p><pre><strong>输入:</strong>nums = [0]<strong><br />输出:</strong>[[],[0]]</pre><p> </p><p><strong>提示:</strong></p><ul>\t<li><code>1 <= nums.length <= 10</code></li>\t<li><code>-10 <= nums[i] <= 10</code></li></ul></div></div>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution\n{\npublic:\n\tvector<vector<int>> subsetsWithDup(vector<int> &nums)\n\t{\n\t\tvector<vector<int>> res;\n\t\tsort(nums.begin(), nums.end());\n\t\tdfs(nums, 0, res);\n\t\treturn res;\n\t}\nprivate:\n\tvector<int> stack;\n\tvoid dfs(vector<int> &nums, int start, vector<vector<int>> &res)\n\t{\n\t\tres.push_back(stack);\n\t\tint last = INT_MIN;\n\t\tfor (int i = start; i < nums.size(); i++)\n\t\t{\n\t\t\tif (last != nums[i])\n\t\t\t{\n\t\t\t\tstack.push_back(nums[i]);\n\t\t\t\tdfs(nums, i + 1, res);\n\t\t\t\tstack.pop_back();\n\t\t\t}\n\t\t\tlast = nums[i];\n\t\t}\n\t}\n};",
    "language": "cpp"
  },
  "node_id": "dailycode-04de312db7184d038e58eb517b6b4977",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600469825"
}