LeetCode: Combinations
来源:互联网 发布:易推客营销软件下载 编辑:程序博客网 时间:2024/05/31 19:50
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
For example,
If n = 4 and k = 2, a solution is:
[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
class Solution {public: vector<vector<int> > combine(int n, int k) { if(n == 0 || k == 0) return result; vector<int> cur; dfs(1, n, k, cur); return result; }private: vector<vector<int> > result; void dfs(int start, int n, int k, vector<int> &cur) { if(cur.size() == k) { result.push_back(cur); return; } for(int i = start; i <= n; i++) { cur.push_back(i); dfs(i+1, n, k, cur); cur.pop_back(); } }};
0 0
- 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
- FPU
- 设计模式之工厂设计模式
- SQLServer 2012 Always on配置全过程
- HttpClient4.0杂谈
- maven 构建可执行 jar ,并引入所需所有依赖 jar
- LeetCode: Combinations
- 11.4 地图大头针 重用标示符
- BigPipe笔记
- PM8001驱动及相关模块分析——综述及初始化
- jquery随机新闻滚动切换效果
- 日语学习之新版初级标准日本语-19 部屋の かぎを 忘れないで ください
- 从两端生长的双向栈-C语言版
- poj_2533_Longest Ordered Su... poj_1260_Pearls hdu_1025_Constructing Roa... poj_2533_Longest Ordered
- POJ 2406 Power Strings(kmp)