Leetcode Problem.47—Permutations II C++实现
2015-06-05 13:09
337 查看
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
For example,
the following unique permutations:
and
全排列,并且去掉重复情况。
我的C++程序!STL算法实现。
For example,
[1,1,2]have
the following unique permutations:
[1,1,2],
[1,2,1],
and
[2,1,1].
全排列,并且去掉重复情况。
我的C++程序!STL算法实现。
vector<vector<int>> permuteUnique(vector<int>& nums) { int len=nums.size(); vector<vector<int>> result; vector <int>temp; sort(nums.begin(),nums.end()); do { for(int i=0;i<len;i++) temp.push_back(nums[i]); result.push_back(temp); temp.clear(); } while (next_permutation(nums.begin(),nums.end())); return result; }
相关文章推荐
- Leetcode Problem.46—Permutations C++实现
- 设计模式C++实现(8)——代理模式
- 面试考题之9.1:数组与字符串(C/C++版)
- C++设计模式——代理模式
- c++实现两个数的交换
- C/C++基础
- C++生成54个不同的随机数
- C++template 5.2
- C语言函数声明
- week14_1.cpp
- Google Mock启蒙篇 [1] (Google C++ Mocking Framework for Dummies 翻译)
- week14_2.cpp
- c++ 适配器模式(adapter)2
- Google Mock启蒙篇 [2] (Google C++ Mocking Framework for Dummies 翻译)
- 【Clone Graph】cpp
- VS2010编写的c++程序输出结果一闪而过怎么解决
- 【C++】多个类的DLL封装及调用
- 写c++代码时,一定要注意初始化!
- PS 图像黑白调整算法(彩色图转灰度图)(VC++)
- java定义在局部的内部类、匿名内部类 (接《c++与java嵌套类比较》)