标签:mission [1] set line end void temp ica cto
Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
Input: [1,2,2] Output: [ [2], [1], [1,2,2], [2,2], [1,2], [] ]
AC code:
class Solution { private: void helper(int begin, int len, vector<int> temp, vector<vector<int>>& res, vector<int> nums) { res.push_back(temp); for (int i = begin; i < len; ++i) { if (i != begin && nums[i] == nums[i-1]) continue; temp.push_back(nums[i]); helper(i+1, len, temp, res, nums); temp.pop_back(); } } public: vector<vector<int>> subsetsWithDup(vector<int>& nums) { vector<int> temp; vector<vector<int>> res; sort(nums.begin(), nums.end()); int len = nums.size(); helper(0, len, temp, res, nums); return res; } };
标签:mission [1] set line end void temp ica cto
原文地址:https://www.cnblogs.com/ruruozhenhao/p/9866112.html