Leetcode 47. Permutations II
来源:互联网 发布:知乎b站三国演义 编辑:程序博客网 时间:2024/06/08 00:05
public class Solution { public List<List<Integer>> permuteUnique(int[] nums) { Arrays.sort(nums); List<List<Integer>> ret = new ArrayList<>(); List<Integer> curr = new ArrayList<>(); boolean[] isVisited = new boolean[nums.length]; dfs(0, nums, curr, ret, isVisited); return ret; } private static void dfs(int pos, int[] nums, List<Integer> curr, List<List<Integer>> ret, boolean[] isVisited) { if (curr.size() == nums.length) { ret.add(new ArrayList<>(curr)); } for (int i=0; i<nums.length; i++) { // simialr with duplicate combinations if (isVisited[i] || (i!=0 && nums[i]==nums[i-1] && !isVisited[i-1])) { continue; } isVisited[i] = true; curr.add(nums[i]); dfs(i+1, nums, curr, ret, isVisited); isVisited[i] = false; curr.remove(curr.size()-1); } }}
0 0
- [LeetCode]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 LeetCode
- Leetcode 47. Permutations II
- LeetCode 47. Permutations II
- LeetCode - 47. Permutations II
- [LeetCode] 47. Permutations II
- leetcode 47. Permutations II
- [LeetCode]--47. Permutations II
- [LeetCode]--47. Permutations II
- [leetcode] 47. Permutations II
- leetcode 47. Permutations II
- Leetcode-47. Permutations II
- [LeetCode]--47. Permutations II
- 102. Binary Tree Level Order Traversal
- Leetcode 211. Add and Search Word - Data structure design
- 布尔巴基的学术风格
- T-SQL 语句(一)—— 数据库操作
- Leetcode 213. House Robber II
- Leetcode 47. Permutations II
- 快速排序算法浅析
- Leetcode 46. Permutations
- Java_每天学习一点点之Java开发实战经典第三章习题
- 装饰者模式
- CKEditor+CKFinder服务器临时文件存储路径的问题
- 如何修改virtualBox下Ubuntu的虚拟内存
- 当jsp页面完全加载完成后执行一个js函数
- 339. Nested List Weight Sum