leetcode Permutations
来源:互联网 发布:大数据需要数据库吗 编辑:程序博客网 时间:2024/06/07 10:30
题目链接
思路:
递归回溯。典型应用
public class Solution { int n; List<List<Integer>> result; List<Integer> temp; boolean isUsed[]; int[]nums; public List<List<Integer>> permute(int[] nums) { n=nums.length; isUsed=new boolean[n]; temp=new LinkedList<Integer>(); result=new LinkedList<List<Integer>>(); this.nums=nums; help(0); return result; } public void help(int step) { if(step==n) { result.add(new LinkedList<Integer>(temp)); return; } for(int i= 0;i<n;i++) { if(!isUsed[i]) { isUsed[i]=true; temp.add(nums[i]); help(step+1); isUsed[i]=false; temp.remove(temp.size()-1); } } }}
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
- Hadoop--Hadoop核心之MapReduce
- NSURLConnection 与 NSURLSession
- Hadoop家族产品学习路线图
- 信息系统项目管理师-业务流程管理知识点
- swift中的常量和变量
- leetcode Permutations
- viewDidLoad, viewWillDisappear, viewWillAppear等方法的区别及各自的加载顺序
- jQuery 关于城市的二级联动
- 功能测试自动化
- 信息系统项目管理师-知识管理知识点
- webservice天气预报实现
- java记——循环打印金字塔数
- 10.14
- Android自定义控件之滑动解锁九宫格