Permutations
来源:互联网 发布:美国标志软件 编辑:程序博客网 时间:2024/06/05 07:06
Permutations
Given a list of numbers, return all possible permutations.
Example
For nums [1,2,3], the permutaions are:
[
[1,2,3],
[1,3,2],
[2,1,3],
[2,3,1],
[3,1,2],
[3,2,1]
]
public ArrayList<ArrayList<Integer>> permute(ArrayList<Integer> nums) { ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); if (nums == null || nums.size() == 0) { return result; } ArrayList<Integer> path = new ArrayList<Integer>(); dfs(result, path, nums); return result; } private void dfs(ArrayList<ArrayList<Integer>> result, ArrayList<Integer> path, ArrayList<Integer> nums) { if (path.size() == nums.size()) { result.add(new ArrayList<Integer>(path)); return; } for (int i = 0; i < nums.size(); i++) { if (path.contains(nums.get(i))) { continue; } path.add(nums.get(i)); dfs(result, path, nums); path.remove(path.size() - 1); } }思路:
1. set大小一致
2. 无重复
3. 不需要pos信息
0 0
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- 集合的全排列
- mysql 语句学习网站
- spring security常用过滤器链的基本介绍
- 模拟退火算法
- 数据结构 总结
- Permutations
- 控件的测试方法
- Ubuntu 14.04下JAVA 1.8和Scala开发环境搭建
- jquery模拟java集合中的map
- 字符串的一些基本操作
- GridView 中getview方法position 0 加载多次问题
- 再探MFC(二)多标签对话框
- arcgis for flex api version3.7 教程:1.添加地图和图层
- Java中守护线程的总结