[LeetCode] Permutations
来源:互联网 发布:ubuntu下ros安装过程 编辑:程序博客网 时间:2024/05/02 04:45
Recursion with backtracking.
class Solution {public: void helper(vector<vector<int> > &result, vector<int> &num, vector<int> cur, vector<bool> used, int n) { if(n==num.size()) { result.push_back(cur); return; } for(int i=0;i<num.size();i++) { if(!used[i]) { cur[n]=num[i]; used[i]=true; helper(result, num, cur, used,n+1); used[i]=false; } } } vector<vector<int> > permute(vector<int> &num) { vector<int> cur; vector<bool> used; for(int i=0;i<num.size();i++) { cur.push_back(0); used.push_back(false); } vector<vector<int> > r; helper(r, num, cur, used, 0); return r; }};
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
- USB 3G上网卡调试记录
- SAS学习(二)
- iOS多线程编程之Grand Central Dispatch(GCD)介绍和使用
- 获得的知识
- 用VisualSVN做项目版本控制
- [LeetCode] Permutations
- 我6个月的学习编程经历:从”大齿怪“到“狂欢者”
- 梁静茹晒巨肚孕照引惊叹 被疑怀双胞胎
- Android基础类之BaseAdapter
- java web开发:ajax技术(三)——JSON在服务器和浏览器之间的传递
- 根据日期得到今天是星期几
- php中heredoc的使用方法
- php实现生成二维码功能
- Struts2如何封装请求参数