Subsets II问题及解法
来源:互联网 发布:淘宝企业开店费用 编辑:程序博客网 时间:2024/05/18 17:25
问题描述:
Given a collection of integers that might contain duplicates, nums, return all possible subsets.
Note: The solution set must not contain duplicate subsets.
示例:
If nums = [1,2,2]
, a solution is:
[ [2], [1], [1,2,2], [2,2], [1,2], []]问题分析:
本题可按照子集生成的方法来做,结合set的性质,最终可以得到结果。
过程详见代码:
class Solution {public: vector<vector<int>> subsetsWithDup(vector<int>& nums) { sort(nums.begin(),nums.end()); set<vector<int>> res;res.insert(vector<int>());int len = nums.size();for (int i = 0; i < len; i++){set<vector<int>> temp = res;for (auto v : res){v.push_back(nums[i]);temp.insert(v);}res = temp;}vector<vector<int>> zres;zres.assign(res.begin(), res.end());return zres; }};
阅读全文
0 0
- Subsets II问题及解法
- Subsets问题及解法
- 【LeetCode】90. Subsets II解法及注释
- Permutations II问题及解法
- Partition to K Equal Sum Subsets问题及解法
- Pascal's Triangle II问题及解法
- Reverse String II问题及解法
- Combination Sum II问题及解法
- Range Addition II问题及解法
- Spiral Matrix II问题及解法
- Unique Paths II问题及解法
- Reverse Linked List II问题及解法
- Path Sum II问题及解法
- Single Number II问题及解法
- Linked List Cycle II问题及解法
- Beautiful Arrangement II问题及解法
- 4Sum II问题及解法
- Add Two Numbers II问题及解法
- Crossing River
- shell脚本的始末
- Android6.0 Wi-Fi Statemachine
- 【android-architecture】TODO-DataBinding
- poj1704(Nim博弈)Georgia and Bob
- Subsets II问题及解法
- C# String与StringBuilder
- Ceres(4):Modeling Non-linear Least Squares APIs(1)
- 快速傅里叶变换(FFT)结果的物理意义是什么?(附Matlab程序)
- ios NSLocale 本地信息
- 11.1数组高级
- Python __call__
- ORDER BY关键字
- 背包问题 新手详解