Permutations II 去掉重复的全排列
2014-11-22 19:08
267 查看
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
For example,
Hide Tags
Backtracking
参考http://blog.csdn.net/morewindows/article/details/7370155
For example,
[1,1,2]have the following unique permutations:
[1,1,2],
[1,2,1], and
[2,1,1].
Hide Tags
Backtracking
class Solution { private: vector<vector<int> > ret; public: void perm(vector<int> &num,int i,int len){ if(i==len){ ret.push_back(num); return; } for(int j=i;j<len;++j){ if(!isSwap(num,i,j)) continue; swap(num[i],num[j]); perm(num,i+1,len); swap(num[j],num[i]); } } bool isSwap(vector<int>& num, int i, int j) { while (num[i] != num[j] && i < j) i++; if (i == j) return true; else return false; } vector<vector<int> > permuteUnique(vector<int> &num) { int len=num.size(); ret.clear(); sort(num.begin(), num.end()); perm(num,0,len); return ret; } };
参考http://blog.csdn.net/morewindows/article/details/7370155
相关文章推荐
- leetcode-47. Permutations II(重复元素全排列)
- Permutations II 字符全排列 去除重复的
- leetcode 47. Permutations II 全排列问题(去掉重复元素)+递归
- Oracle查询重复记录,分页和去掉重复数据的查询语句
- SQL 去掉两个表中重复的数据
- 使用泛型去掉数组中的重复数字
- ASP.NET DataTable去掉重复行的2种方法
- 数组去掉重复值、删除元素、添加元素
- mysql查询所有记录,并去掉重复的记录
- java与js给数组去掉重复字符串
- java去掉list中的重复元素
- web优化之-mvc js动态合并 动态压缩 去掉js重复引用 js缓存 js延迟加载
- DISTINCT 去掉重复记录
- 【ZOJ】3841 Card (搜索+组合数学(重复元素的全排列)
- PL SQL中如何去掉字符串中重复的字符
- 如何去掉矩阵中的重复行
- Distinct 去掉重复 order by
- java去掉重复元素
- 如何去掉ArrayList中重复的集合----元素为集合
- 黑马程序员---123-456--789---123-2把类似的字符串中重复符号去掉