leecode:combinations
来源:互联网 发布:用邮箱怎么注册淘宝账号 编辑:程序博客网 时间:2024/05/20 08:23
Given two integers n and k, return all possible combinations ofk 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 findAllCombinations(vector<vector<int> > &r, vector<int> &t, int n, int k, int num) { if(t.size() == k) { r.push_back(t); return; } for(int i = num; i <= n; i++) { t.push_back(i); findAllCombinations(r, t, n, k, i + 1); t.pop_back(); } } vector<vector<int> > combine(int n, int k) { vector<vector<int> > res; vector<int> tmp; findAllCombinations(res, tmp, n, k, 1); return res; }};
0 0
- leecode:combinations
- leecode 解题总结:77. Combinations
- leecode 解题总结:17. Letter Combinations of a Phone Number
- leecode
- LeeCode
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- Combinations
- andorid(1) ArreyAdapter 自定义使用listview
- BeagleboneBlack学习笔记系列
- 岸部真明 指弹曲 Flower
- 数据库索引,你该了解的几件事
- HDU 2151 Worm (记忆化搜索) 水题
- leecode:combinations
- 数据库事务
- UNIX环境高级编程之----多线程技术(2)
- TransitionDrawable使用不当导致内存泄露
- sqlserver查询数据的所有表名和行数
- 浅谈java入门
- Android Activity的启动模式
- iOS 多线程学习笔记 —— dispatch_async在serial queue中的异常
- 使用ViewPager实现左右滑动效果