[leetcode] Combinations
来源:互联网 发布:大众 软件 编辑:程序博客网 时间:2024/05/01 18:43
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) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<vector<int> > a; vector<vector<int> > b; if(n==k){ vector<int> tmp(k); for(int i=0 ; i<n ; i++) tmp[i]=i+1; a.push_back(tmp); return a; } if(k==1){ vector<int> tmp(1); for(int i=1 ; i<=n ; i++){ tmp[0]=i; a.push_back(tmp); } return a; } a=combine(n-1,k-1); for(int i=0 ; i<a.size() ; i++) a[i].push_back(n); b=combine(n-1,k); a.insert(a.begin(),b.begin(),b.end()); return a; }};
- 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
- android官方开发文档地址
- 数据库数据一致性——事务和存储过程
- jquery 插件bgStretcher 切换背景图片
- Windows程序窗口置前台的几种方法
- DB2 控制中心菜单中文乱码问题
- [leetcode] Combinations
- hdu 1242 Rescue(bfs)
- 使用char **ptr实现一个动态二维数组
- NSArray的排序方法
- virutal Box 解决导入.vdi文件时报“uuid is exists”错误 个人总结.
- oracle10g字符集的查看与修改
- CHK文件的恢复
- Windows核心编程之 用户模式下的线程同步 读写锁和条件变量
- 人生如烟花,只要曾经绚烂过,便不枉此生