LeetCode 046 Permutations
来源:互联网 发布:matlab哈密顿回路算法 编辑:程序博客网 时间:2024/05/16 10:47
题目描述
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].
分析
代码
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
0 0
- LeetCode 046 Permutations
- LeetCode: Permutations II [046]
- LeetCode 046 Permutations
- LeetCode 046 Permutations
- leetcode 046 Permutations
- [LeetCode]046-Permutations
- LeetCode 046 Permutations
- leetcode 046 —— Permutations
- leetcode之路046 Permutations
- leetcode解题方案--046--Permutations
- 【LeetCode】Permutations && Permutations II
- leetcode: Permutations/Permutations II
- leetcode Permutations & Permutations II
- [Leetcode]Permutations && Permutations II
- LeetCode: Permutations
- LeetCode: Permutations
- [Leetcode] Permutations
- [LeetCode] Permutations
- 获得 1000 个赞的程序员高薪职业建议
- TableViewCell分割线为一个像素点
- 图片上下左右居中
- pAdTy_-4 与其它应用程序的交互
- 财务报表开发实例分析:几个通用维度介绍与关键点
- LeetCode 046 Permutations
- 八皇后问题
- swift 快速奔跑的兔几 本节的内容是:SceneKit 第一说 创建一个3D胶囊
- android获取网络数据
- android 如何去获取手机Gps的信号强度
- sql异常
- 为什么我用VS2010做EXTPB.NET程序,有些文件没有发布出去?
- JQuery.Ajax之错误调试帮助信息
- 【知识】Eclipse中搜索的使用