leetcode---Permutations II
来源:互联网 发布:cool edit for mac版 编辑:程序博客网 时间:2024/05/19 23:01
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: vector<vector<int>> ans; vector<int> tmp; bool canSwap(int i, int j, vector<int>& nums) { for(int k=i; k<j; k++) if(nums[k] == nums[j]) return false; return true; } void dfs(int depth, vector<int>& nums) { if(depth >= nums.size()-1) { tmp.clear(); for(int i=0; i<nums.size(); i++) tmp.push_back(nums[i]); ans.push_back(tmp); return; } for(int i=depth; i<nums.size(); i++) { if(canSwap(depth, i, nums)) { swap(nums[depth], nums[i]); dfs(depth+1, nums); swap(nums[depth], nums[i]); } } } vector<vector<int>> permuteUnique(vector<int>& nums) { dfs(0, nums); return ans; }};
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
- SurfaceComposerClient object 问题
- 装饰者模式-c++实现
- Java设计模式之构建者模式
- Oracle中对Scott用户解锁
- 【Unity Shader】新书封面 — Low Polygon风格的渲染
- leetcode---Permutations II
- Java 多线程操作
- android的工具类
- 狼爪兔子 gcd
- leetcode---Pow(x, n)---快速幂
- CSS3 animation
- SpringMVC配置<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" />访问页面404错误
- Mysql查询使用Limit优化
- JSP中的相对路径和绝对路径