leetcode Permutations II
来源:互联网 发布:微星 主机 知乎 编辑:程序博客网 时间:2024/06/14 05:54
先上题:
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]
.
class Solution {public:void dfs(vector<vector<int> >& result, vector<int>& tmp, vector<int>& num){if (num.empty()){result.push_back(tmp);return;}map<int, bool> mapping;for (int i = 0; i < num.size(); i++){mapping[num[i]] = false;}for (int i = 0; i < num.size(); i++){if (mapping[num[i]] == false){tmp.push_back(num[i]);mapping[num[i]] = true;auto iter = num.begin();iter += i;vector<int> tmpA = num;num.erase(iter);dfs(result, tmp, num);num = tmpA;tmp.pop_back();}}}vector<vector<int> > permuteUnique(vector<int> &num){vector<vector<int> > result;if (num.empty()){return result;}vector<int> tmp;dfs(result, tmp, num);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
- IOS 中storyboard拼接方案
- Android 程序框架设计
- iOS8开发~Xcode6下载
- QT设置界面相关问题
- Android近场通信---NFC基础(五)
- leetcode Permutations II
- 快速排序Java代码
- 六 算法
- 瑞文代码推土机(作品2)
- 发布mvc3 web应用程序 iis7 错误 HTTP 错误 404.2 - Not Found.
- Jasperreports导出PDF、web上html的几个实用连接
- bug分类
- 如何辨别正品舒热佳汽车膜?
- java 将程序企业化