LeetCode 46. Permutations
来源:互联网 发布:淘宝卖家发货怎么打包 编辑:程序博客网 时间:2024/06/18 16:43
public class Solution { public List<List<Integer>> permute(int[] nums) { List<List<Integer>> list = new ArrayList<List<Integer>>(); int len = nums.length; if (len == 1) { List<Integer> l = new ArrayList<Integer>(); l.add(nums[0]); list.add(l); return list; } Set<Integer> set = new HashSet<Integer>(); for (int i = 0; i < len; i++) set.add(nums[i]); for (int i = 0; i < len; i++) { int num = nums[i]; set.remove(num); int[] subNums = new int[len - 1]; int j = 0; for (int n : set) subNums[j++] = n; List<List<Integer>> subList = permute(subNums); for (List<Integer> l : subList) l.add(num); list.addAll(subList); set.add(num); } return list; }}
0 0
- [LeetCode]46.Permutations
- LeetCode 46.Permutations
- 46. Permutations Leetcode Python
- LeetCode --- 46. Permutations
- [Leetcode] 46. Permutations
- [leetcode] 46.Permutations
- LeetCode 46. Permutations DFS
- 46. Permutations LeetCode
- Leetcode 46. Permutations
- leetcode 46. Permutations
- LeetCode *** 46. Permutations
- LeetCode 46. Permutations
- leetcode 46. Permutations
- LeetCode - 46. Permutations
- 【leetcode】46. Permutations
- leetcode 46. Permutations
- [LeetCode] 46. Permutations
- leetcode 46. Permutations
- web项目导出word之用blob保存的图片
- PAT乙级1025
- 随机数
- Linux输出重定向,vim与gedit
- MySQL常用命令
- LeetCode 46. Permutations
- LINUX系统下caffe开发环境和python接口的配置(利用GPU和CUDNN加速)
- Baekeland and Hartmann report that the "short sleepers"
- Centos7下载地址
- 分发巧克力问题
- 设计模式--单例模式学习笔记
- 第四天(HttpServlet类)
- DNS正反向解析和主从同步配置
- maven常用命令