Leetcode Combinations
来源:互联网 发布:vscode编译c语言 编辑:程序博客网 时间:2024/05/18 01:23
简单的dfs。
class Solution {public: vector<vector<int> > combine(int n, int k) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. ans.clear(); dfs(n, k, 0); return ans; } void dfs(int n, int k, int cnt){ if(cnt == k){ ans.push_back(v); return ; } for(int i = 1; i <= n; i++){ if(v.empty() || i > v[v.size()-1]){ v.push_back(i); dfs(n, k, cnt+1); v.pop_back(); } } } vector<vector<int> > ans; vector<int> v;};
- 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
- 关于一个页面里面有两个按钮的解决。
- 黑马程序员_银行业务调度系统
- MYSQL远程连接数据
- (Relax 数论1.26)POJ 1496 Word Index(计算一个字符串在字典中的位置)
- Microsoft SharePoint 2010, is it a true Document Management System? 微软SharePoint 2010,它是真正的文档管理系统吗?
- Leetcode Combinations
- JS匿名自执行函数
- 使用mongodb的js来统计数据
- 指针变量向函数中传递的陷阱及解决方法
- n以内约数最多的数
- 搜索引擎——原理技术与系统第二章第五节
- memcached的安装和基本操作
- Python 多重继承mro
- Linux shell脚本编程之调试