[LeetCode 题解]:Combinations
2024-09-26 22:11:00
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],
]
DFS,递归
class Solution {
public:
vector<vector<int> > ans;
vector<int> vi;
int k_start,n_start;
void DFS(int Count,int start)
{
if(Count== k_start)
{
ans.push_back(vi);
return;
}
for(int i=start;i<n_start;i++)
{
vi[Count] = i+;
DFS(Count+, i+);
}
}
vector<vector<int> > combine(int n, int k) {
ans.clear();
vi.resize(k);
k_start = k;
n_start = n;
DFS(,);
return ans;
}
};
最新文章
- JSON Accelerator真是个好东西...
- 使用DocX开源组件,实现动态数据的填充。
- HTMLTestRunner修改Python3的版本
- header的安全配置指南
- DataTable以列分组
- iOS部分其他知识
- Java类的加载、链接和初始化
- Handler具体解释系列(四)——利用Handler在主线程与子线程之间互发消息
- [PowerShell] Backup Folder and Files Across Network
- 【Unity3D自学记录】Unity3D网络之Socket聊天室初探
- android 自己定义通知栏遇到的问题
- 优秀Java程序员必须了解的GC工作原理(转)
- JavaScript系列文章:详解正则表达式之三
- python网络编程之网络主机信息
- Hibernate一对多双向关联映射
- js事件、事件流以及target、currentTarget、this那些事
- python 最大连续子数组的和
- vue脚手架---vue-cli
- moodle 笔记
- iOS pods编译原理