Permutations
来源:互联网 发布:非正式会谈oo的淘宝店 编辑:程序博客网 时间:2024/06/07 01:57
https://leetcode.com/problems/permutations/
题意:
全排列,数组元素各不相同
分析:
递归解法
注意:List中的list们,每个都是不同的,所有在inner加入list的时候,要重新new一个list
public class Solution { public List<List<Integer>> permute(int[] nums) { List<List<Integer>> list = new ArrayList<List<Integer>>(); boolean[] visited = new boolean[nums.length]; List<Integer> inner = new ArrayList<Integer>(); permute(nums, inner, visited, list); return list; } public void permute(int[] nums, List<Integer> inner, boolean[] visited, List<List<Integer>> list) { if(inner.size() == nums.length){ list.add(new ArrayList<Integer>(inner)); return; } for(int i = 0; i < nums.length; i++){ if(visited[i])continue; visited[i] = true; inner.add(nums[i]); permute(nums, inner, visited, list); visited[i] = false; inner.remove(inner.size() - 1); } }}
0 0
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- 没有main函数生成可执行程序的几种方法 http://www.linuxidc.com/Linux/2013-09/90061.htm
- string 与 CString 转化
- mysql常用命令
- C语言封装disruptor
- Effective C++——条款51(第8章)
- Permutations
- html点击文字显示图片
- 数组、字典转化为json字符串
- mysql 5.6 utf-8 编码设置
- hadoop集群模式下导入数据到hbase上报错
- C语言与C++中点运算符与箭头运算符的区别
- 设计模式之组合模式
- IOS:IOS9适配中出现的一些问题
- No EditorOptionDefinition Export Found Error的问题