47. Permutations II
2016-03-08 10:59
351 查看
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].
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; } }
相关文章推荐
- 【LeetCode】283. Move Zeroes
- #1064-You hava an error in your SQL syntax
- k近邻法中kd-tree树的创建
- codeforces #345 div.2 B Beautiful Paintings
- Struts内置类型转换器
- kafka实践
- 纯CSS修改浏览器的默认滚动条样式
- CSS 属性 - 伪类和伪元素
- SocketServer model_use
- Codeforces Round #345 (Div. 2) E. Table Compression 并查集
- JavaScript笔记
- Ambiguous column name
- ClamAV源码配置安装测试
- Leetcode:102. Binary Tree Level Order Traversal(JAVA)
- MapGIS6.7_学习中遇到的问题(2):去除飞点
- Android中使用Vectors(2)绘制优美的路径动画
- linux中more与less的区别
- php学习笔记之:环境配置(一)
- RHEL4 安装yum
- wordpress发布文章404