Leetcode--Permutations II
来源:互联网 发布:骷髅骨架软件 编辑:程序博客网 时间:2024/06/05 00:57
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
For example,[1,1,2]
have the following unique permutations:[1,1,2]
, [1,2,1]
, and [2,1,1]
.
思路:在Permutations的解法上,处理重复问题。
class Solution {public: set<vector<int>> res; void swap(int *a,int *b) { int temp=*a; *a=*b; *b=temp; } void function(vector<int>&num,int i) { if(i==num.size()-1) { res.insert(num); } else{ for(int j=i;j<num.size();j++) { if(j==i) function(num,i+1); else if(j>i&&num[j]!=num[i]){ swap(&num[i],&num[j]); function(num,i+1); swap(&num[i],&num[j]); } } } } vector<vector<int> > permuteUnique(vector<int> &num) { if(num.size()>0) function(num,0); vector<vector<int>> result(res.begin(),res.end()); return result; }};
0 0
- 【LeetCode】Permutations && Permutations II
- leetcode: Permutations/Permutations II
- leetcode Permutations & Permutations II
- [Leetcode]Permutations && Permutations II
- Leetcode: Permutations and Permutations II
- leetcode-permutations and permutations II
- Leetcode:Permutations与Permutations II
- LeetCode: Permutations II
- LeetCode Permutations II
- LeetCode: Permutations II
- [Leetcode] Permutations II
- [LeetCode] Permutations II
- [Leetcode] Permutations II
- leetcode Permutations II
- [LeetCode]Permutations II
- leetcode - Permutations II
- LeetCode-Permutations II
- [leetcode] Permutations II
- java文件操作大全
- 修改Android设备信息,如修改手机型号为iPhone7黄金土豪版!
- 可以把JPG图片转成PDF的格式转换器
- 完美洗牌算法
- Windows下ADB默认的5037端口被占用,解决方案。
- Leetcode--Permutations II
- Access Mode
- Linux指令笔记2
- 谷歌推Physical Web取代智能设备的app
- SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
- 用python做oj上的简单题(持续更新中.......)
- Foundation框架之NSArray
- 哪种编程语言最适合你
- win7 64位“不是内部命令和外部命令,也不是可运行的程序和批处理文件”错误的解决办法。