LeetCode 46. Permutations(同47,只是不包含重复数字)
来源:互联网 发布:外国人评价三体 知乎 编辑:程序博客网 时间:2024/06/07 17:16
Given a collection of distinct numbers, return all possible permutations.
For example,[1,2,3]
have the following permutations:
[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]
public class Solution { public List<List<Integer>> permute(int[] nums) { if(nums==null||nums.length==0) return null; int len = nums.length; int[] isUsed = new int[len]; List<List<Integer>> result = new ArrayList<List<Integer>>(); List<Integer> store = new ArrayList<Integer>(); dfs(result,isUsed,store,nums); return result; } public void dfs(List<List<Integer>> result, int[] isUsed, List<Integer> store, int[] nums) { if(store.size()==nums.length){ result.add(new ArrayList<>(store)); return; } for(int i=0;i<nums.length;i++){ if(isUsed[i]==1) continue; store.add(nums[i]); isUsed[i]=1; dfs(result,isUsed,store,nums); isUsed[i]=0; store.remove(store.size()-1); }}}
0 0
- LeetCode 46. Permutations(同47,只是不包含重复数字)
- 不包含重复数字的抽样算法
- Leetcode: 217. Contains Duplicate(数组是否包含重复数字)
- leetcode-46. Permutations(非重复元素全排列)
- leetcode-46、47 Permutations/II 数字的排列组合
- 随机生成0~9十个数字,十个数字不重复(包含升序,降序)
- 求全排列,不重复(Permutations II)
- 349. Intersection of Two Arrays不重复的记录两个数组中共同的数字
- LeetCode 46 Permutations + LeetCode 47 Permutations II
- 【JLOI2011】不重复数字
- BZOJ2761 不重复数字
- [BZOJ2761] 不重复数字
- 不重复数字求和
- [LeetCode]46.Permutations
- LeetCode 46.Permutations
- 46. Permutations Leetcode Python
- LeetCode --- 46. Permutations
- [Leetcode] 46. Permutations
- java基础总结(3)--框架
- SQLServer 和numa
- 腾讯云centos7 安装语言环境及java生产环境
- 题目1157:中位数
- jquery基础
- LeetCode 46. Permutations(同47,只是不包含重复数字)
- 反转链表
- Eclipse在高分屏下图标过小的解决方法
- NandFlash、NorFlash区别
- Dojo对AMD的简述
- HDU-2668(Daydream) 求最长的不重复子串
- python第三方库numpy的使用
- PHP程序开发之.csv文件导出方法
- 题目1158:买房子