47. Permutations II
来源:互联网 发布:信越7783硅脂淘宝 编辑:程序博客网 时间:2024/05/18 03:32
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 { List<List<Integer>> result = new ArrayList<List<Integer>>(); //先定义 public List<List<Integer>> permuteUnique(int[] nums) { Arrays.sort(nums); //进行排序 permutefunc(nums,nums.length,new ArrayList<Integer>(),new HashSet<Integer>()); //使用了HashSet return result; } public void permutefunc(int[] nums,int k,List<Integer> array,Set<Integer> chosen){ if(k==0){ result.add(new ArrayList(array)); return; } for(int i=0;i<nums.length;i++){ if(i>0&&nums[i]==nums[i-1]&&!chosen.contains(i-1))continue; if(chosen.add(i)){ array.add(nums[i]); permutefunc(nums,k-1,array,chosen); array.remove(array.size()-1); chosen.remove(i); } } return; }}
0 0
- 46. Permutations && 47. Permutations II
- 46. Permutations, 47. Permutations II
- [LeetCode]47.Permutations II
- LeetCode 47.Permutations II
- LeetCode --- 47. Permutations II
- [Leetcode] 47. Permutations II
- [leetcode] 47.Permutations II
- 47.Permutations II
- 47. Permutations II
- LeetCode 47. Permutations II
- 47. Permutations II
- 47. Permutations II LeetCode
- 47. Permutations II
- 47. Permutations II
- 47. Permutations II
- 47. Permutations II
- Leetcode 47. Permutations II
- 47. Permutations II
- jquery 取值 radio 问题
- #1064-You hava an error in your SQL syntax
- codeforces #345 div.2 B Beautiful Paintings
- 【leetcode】【169】Majority Element
- CK-----------------ocx端口打开失败
- 47. Permutations II
- 回车和换行
- windows远程连接Ubuntu14.04—vnc4server
- JAVA CAS实现原理与使用
- 在来电监听服务中动态注册去电广播(BroadcastRecevier)
- runtime基础教程(1)-OC元素认知
- Android Http 助手类(麻雀虽小),实现文件上/传下载,Cookie机制
- 判断是否有某个class
- AFHTTPSessionManager