Leetcode: Combinations
来源:互联网 发布:毛概网络课程答案 编辑:程序博客网 时间:2024/05/18 18:21
http://oj.leetcode.com/problems/combinations/
class Solution {private: vector<bool> used; vector<vector<int> > res; vector<int> current;public: // It asks for all the combinations, so we need the variable last to avoid duplications void DFS(int n, int k, int depth, int last=-1){ if(depth==k){ res.push_back(current); } else{ for(int i=last+1;i<n;i++){ if(used[i]==false){ current[depth]=i+1; used[i]=true; DFS(n, k, depth+1, i); used[i]=false; } } } } vector<vector<int> > combine(int n, int k) { used.clear(); res.clear(); current.clear(); if(k==0) return res; for(int i=0;i<n;i++) used.push_back(false); for(int i=0;i<k;i++) current.push_back(0); DFS(n, k, 0); return res; }};
- LeetCode: Combinations
- LeetCode: Combinations
- LeetCode Combinations
- [Leetcode] Combinations
- [LeetCode] Combinations
- Leetcode: Combinations
- LeetCode Combinations
- [Leetcode] Combinations
- [Leetcode] Combinations
- [leetcode] Combinations
- [LeetCode]Combinations
- [leetcode]Combinations
- LeetCode-Combinations
- [leetcode] Combinations
- LeetCode - Combinations
- 【Leetcode】Combinations
- Leetcode: Combinations
- 【leetcode】Combinations
- Leetcode: Search in Rotated Sorted Array II
- Web 服务学习资源
- c编程邮件传输
- 黑马程序员--整理一下一些有用的类
- 阶段总结
- Leetcode: Combinations
- OSCache
- Node.js, 使用 Buffers 操作,编码、解码,二进制数据。
- 写给换工作和找工作的同学
- 上海市二○○九年(上半年)会计从业资格统一考试
- Linux内核中链表实现
- 三角函数--char4
- 奇虎360可以干大事
- JAVA操作Excel表格