leetcode--Permutations
来源:互联网 发布:库卡机器人编程视频 编辑:程序博客网 时间:2024/06/05 22:30
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 class Solution { public List<List<Integer>> permute(int[] nums) {List<List<Integer>> res = new ArrayList<List<Integer>>();solve(nums, 0, res);return res; } public void solve(int[] nums,int i,List<List<Integer>> res){if(i==nums.length-1){List<Integer> t = new ArrayList<Integer>();for(int j=0;j<nums.length;j++){t.add(nums[j]);}res.add(t);}for(int j=i;j<nums.length;j++){int t = nums[i];nums[i] = nums[j];nums[j] = t;solve(nums, i+1, res);t = nums[i];nums[i] = nums[j];nums[j] = t;}}}
0 0
- 【LeetCode】Permutations && Permutations II
- leetcode: Permutations/Permutations II
- leetcode Permutations & Permutations II
- [Leetcode]Permutations && Permutations II
- LeetCode: Permutations
- LeetCode: Permutations
- [Leetcode] Permutations
- [LeetCode] Permutations
- Leetcode: Permutations
- [Leetcode] Permutations
- [Leetcode] Permutations
- [LeetCode]Permutations
- LeetCode-Permutations
- [leetcode] permutations
- LeetCode - Permutations
- Leetcode: Permutations
- 【leetcode】Permutations
- 【LeetCode】Permutations
- linux中使用内存映射(mmap)操作文件的方法
- 汽车刹车油保养小常识
- 快速读取SharedPreferences数据
- Linux tar包安装Nginx
- mysql数据库的表copy
- leetcode--Permutations
- HttpClient访问的多线程问题
- python 正则字符串替换 re.sub 替换输入参数字符串inStrings 所有的一个或多个空格替换为newstring
- Uva - Uva272 - TEX Quotes
- qt for v210
- 用支持向量机做OCR(MATLAB)
- mysql 5.6.24 安装
- 数组实现大数相加
- HTML特殊字符编码对照表