[刷题]Permutations
来源:互联网 发布:手机扫描录入软件 编辑:程序博客网 时间:2024/05/21 11:32
[LintCode]Permutations
class Solution { /** * @param nums: A list of integers. * @return: A list of permutations. */ public ArrayList<ArrayList<Integer>> permute(ArrayList<Integer> nums) { // 2015-08-28 // nums不含重复元素,每个元素只可以使用一次 // 解集中不可以含重复解 ArrayList<ArrayList<Integer>> rst = new ArrayList<>(); if (nums == null || nums.size() == 0) { return rst; } Collections.sort(nums); ArrayList<Integer> list = new ArrayList<>(); helper(nums, rst, list); return rst; } private void helper(ArrayList<Integer> nums, ArrayList<ArrayList<Integer> rst, ArrayList<Integer> list) { if (list.size() == nums.size()) { rst.add(new ArrayList<Integer>(list)); return; } for (int i = 0; i < nums.size(); i++) { if (list.contains(nums.get(i))) { continue; } list.add(nums.get(i)); helper(nums, rst, list); list.remove(list.size() - 1); } return; }}
0 0
- [刷题]Permutations
- [刷题]Permutations II
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- js - videojs视频播放,支持ie8
- 以XML作数据库的考生成绩管理系统的实现
- When to use __new__ vs __init__
- js自定义对象
- (五)Spark源码理解之BroadcastManager
- [刷题]Permutations
- Android XML解析技术——DOM
- Android自定义对话框
- zbox的测试例——selectAll+selectInverse
- 漫画:应对海量数据 实现灵活拓展云存储
- JNI中使用LOGCAT 进行Debug
- iOS "xxx" is missing from working copy
- MS SQLserver mysql
- 第二周上机项目1 旱冰场造价