Leetcode: Combinations
来源:互联网 发布:泳衣品牌知乎 编辑:程序博客网 时间:2024/05/01 19:41
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],]
void comb(int n, int index, int k, vector<vector<int>> &res, vector<int> &path) { if(path.size() == k){res.push_back(path);return;}for(int i = index+1; i <=n; i++){path.push_back(i);comb(n,i,k,res,path);path.pop_back();}}vector<vector<int> > combine(int n, int k) { // Note: The Solution object is instantiated only once vector<vector<int>> res;if(n<k || n<1 || k<1)return res;vector<int> path;for(int i =1; i <= n; i++){path.push_back(i);comb(n,i,k,res,path);path.pop_back();} }
- 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
- emeditor的快捷键
- JAVA学习路线图---(JAVA1234)
- 设计模式——学习笔记——门面模式Facade——基础篇
- sdutoj 1269 走迷宫
- ssh 免密码登录
- Leetcode: Combinations
- unix 环境高级编程 chap5 - 标准I/O
- SAE 搭建 Discuz
- hdu 4462 Scaring the Birds 状态压缩
- 生产者/消费者模式 (一)“生产者/消费者模式”介绍
- 生产者/消费者模式(二)如何确定数据单元
- 生产者/消费者模式(三)队列缓冲区
- 生产者/消费者模式 (四)注意事项
- C++友元小结