leetcode---combinations---dfs
来源:互联网 发布:网络信用卡有哪些 编辑:程序博客网 时间:2024/06/02 02:51
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: void dfs(int dep, int n, int k, vector< vector<int> > &ans, vector<int> &tmp) { if(tmp.size() == k) { ans.push_back(tmp); } for(int i=dep; i<=n; i++) { tmp.push_back(i); dfs(i+1, n, k, ans,tmp); tmp.pop_back(); } } vector<vector<int> > combine(int n, int k) { vector<int> tmp; vector< vector<int> > ans; dfs(1, n, k, ans, tmp); return ans; }};
阅读全文
0 0
- Leetcode dfs Combinations
- leetcode---combinations---dfs
- LeetCode-77-Combinations dfs+剪枝
- LeetCode Combinations Problem using backtracing and DFS
- 【LeetCode】77. Combinations,DFS的变形应用
- 【DFS】Combinations
- DFS Combinations
- Leetcode dfs Letter Combinations of a Phone Number
- Leetcode Letter Combinations of a Phone Number DFS
- LeetCode Letter Combinations of a Phone Number DFS
- LeetCode OJ-17.Letter Combinations of a Phone Number(DFS)
- LeetCode: Combinations
- LeetCode: Combinations
- LeetCode Combinations
- [Leetcode] Combinations
- [LeetCode] Combinations
- Leetcode: Combinations
- LeetCode Combinations
- C++多位整形数据相乘的代码
- OutOfMemoryError系列(6): Out of swap space?
- #define PINT int*与typedef int *SINT的区别.
- Java后台框架篇--Spring中Bean的生命周期
- Java SE8 Lambda 基础入门---怎么写lambda表达式
- leetcode---combinations---dfs
- ASM常用命令
- 【BZOJ 1093】【ZJOI 2007】【最大半连通子图】【tarjan强连通分量】【拓扑排序dp】
- Java BufferedReader readLine方法i
- windows中修改tomcat运行窗口的名字
- 如何持久化会话级别的Session
- 【Codeforces150E】Freezing with Style
- 先排序,再分组,再排序,再将组内元素合并
- 关于面向对象和面向过程