Permutations
来源:互联网 发布:php音频上传代码 编辑:程序博客网 时间:2024/06/07 00:13
Given a list of numbers, return all possible permutations.
class Solution { /** * @param nums: A list of integers. * @return: A list of permutations. */ public List<List<Integer>> permute(int[] nums) { List<List<Integer>> results = new ArrayList<>(); if (nums == null) { return results; } if (nums.length == 0) { results.add(new ArrayList<Integer>()); return results; } List<Integer> result = new ArrayList<>(); dfsHelper(nums, results, result); return results; } private void dfsHelper(int[] nums, List<List<Integer>> results, List<Integer> result) { if (result.size() == nums.length) { results.add(new ArrayList<Integer>(result)); } for (int i = 0; i < nums.length; i++) { if (result.contains(nums[i])) { continue; } result.add(nums[i]); dfsHelper(nums, results, result); result.remove(result.size() - 1); } }}
0 0
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- 99. Recover Binary Search Tree
- Maven resources plugin 损坏二进制数据
- XMPP协议详解
- 最大子序列、最长递增子序列、最长公共子串、最长公共子序列、字符串编辑距离
- 全面了解 Nginx 主要应用场景
- Permutations
- [bzoj2534]Uva10829L-gap字符串
- 二叉树2(二叉查找树的插入、查找、删除、遍历)
- java.lang.ClassNotFoundException:com.mysql.jdbc.Driver
- css代码语法
- 你想知道的 Watch App 开发
- Permutations II
- nohup
- 逻辑回归模型(Logistic Regression, LR)