Permutations II
来源:互联网 发布:软件实施工程师待遇 编辑:程序博客网 时间:2024/05/16 00:28
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]
.
public class Solution { public void permuteUnique(int[] num, ArrayList<ArrayList<Integer>> res, ArrayList<Integer> tem) { if(num.length == 0) { ArrayList<Integer> clone = new ArrayList<Integer>(tem); res.add(clone); return; } ArrayList<Integer> cache = new ArrayList<Integer>(); for(int i=0; i<num.length; i++) { if(!cache.contains(num[i])) { cache.add(num[i]); int[] nextNum = new int[num.length-1]; int nextLen = 0; for(int j=0; j<num.length; j++) { if(j!=i) nextNum[nextLen++] = num[j]; } tem.add(num[i]); permuteUnique(nextNum, res, tem); tem.remove(tem.size()-1); } } return; } public ArrayList<ArrayList<Integer>> permuteUnique(int[] num) { ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>(); ArrayList<Integer> tem = new ArrayList<Integer>(); permuteUnique(num, res, tem); return res; }}
0 0
- 【LeetCode】Permutations && Permutations II
- leetcode: Permutations/Permutations II
- leetcode Permutations & Permutations II
- [Leetcode]Permutations && Permutations II
- Permutations and Permutations II
- Permutations && Permutations ii
- Permutations II
- Permutations II
- Permutations II
- Permutations II
- Permutations II
- Permutations II
- Permutations II
- Permutations II
- Permutations II
- Permutations II
- Permutations II
- Permutations II
- Unity3D NGUI中使用.9png
- 如何让Redhat Linux启动时进入字符终端模式(不进入XWindow)
- Magento: 通过category name获取category信息
- MFC中combobox中的addstring 报错问题
- 新进初级管理人员的辛酸
- Permutations II
- C#向串口发指令
- JS点击事件触发弹出窗口样式控制
- 十大WordPress安全设置技巧
- magento:如何改变产品的排序方式
- Android GPS, Location Manager教程
- iOS Appdelegate代理方法说明和触发条件
- ramp
- linux下如何把时间转成秒数,或把秒数转换成标准时间格式