LeetCode 046 Permutations
2015-11-11 10:00
393 查看
题目描述
Given a collection of 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], and [3,2,1].
分析
代码
[code] public List<List<Integer>> permute(int[] nums) { if (nums == null || nums.length == 0) { return new ArrayList<List<Integer>>(); } ArrayList<List<Integer>> rt = new ArrayList<List<Integer>>(); if (nums.length == 1) { rt.add(new ArrayList<Integer>(Arrays.asList(nums[0]))); } else { for (int i = 0; i < nums.length; i++) { for (List<Integer> l : permute(resetof(nums, i))) { l.add(nums[i]); rt.add(l); } } } return rt; } private int[] resetof(int[] nums, int index) { int[] rt = new int[nums.length - 1]; int s = 0; for (int i = 0; i < nums.length; i++) { if (i != index) { rt[s++] = nums[i]; } } return rt; }
参考网址
Permutations相关文章推荐
- ASP.NET easyUI--datagrid 通过ajax请求ASP.NET后台数据的分页查询
- MySQL存储过程中的3种循环
- EF学习小记
- [Atom] Cannot install package behind a proxy on Win7
- java 重载和重写的区别
- 射频识别技术漫谈(16)——Mifare UltraLight
- 获得 1000 个赞的程序员高薪职业建议
- TableViewCell分割线为一个像素点
- WebRTC中peerconnectclient&server 简析
- 图片上下左右居中
- (NO.00003)iOS游戏简单的机器人投射游戏成形记(十五)
- asp.net 信息管理系统中的需填写数据的键值对获取方法
- win10预览版10586怎么升级?win10 10240升级10586的图文教程
- Java中equals和==的区别
- ios的一些开源资源
- (NO.00003)iOS游戏简单的机器人投射游戏成形记(十五)
- (NO.00003)iOS游戏简单的机器人投射游戏成形记(十五)
- JVM解析01-平台无关性
- 杂谈学习的一点经验
- Zookeeper-Zookeeper client