【Leetcode】Combinations
来源:互联网 发布:python int函数 编辑:程序博客网 时间:2024/05/01 13:24
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],]
这个可以用深搜,在搜索过程中用vector保存中间结果,一旦满足条件就将其输出。
class Solution {public:vector<vector<int> > res;vector<int> com;void combine(int n, int k, int start){if(k==0){res.push_back(com);return;}if(start>n) return;com.push_back(start);combine(n,k-1,start+1);com.pop_back();combine(n,k,start+1);}vector<vector<int> > combine(int n, int k) {// Start typing your C/C++ solution below// DO NOT write int main() functionres.clear();com.clear();combine(n,k,1);return res;}};
- 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 开关机动画显示源码分析
- VMware中使用nat连接时如何配置静态ip
- n*n的网格,从左上角到右下角有多少条线路
- 最小二乘法直线拟合
- 主元素问题
- 【Leetcode】Combinations
- netstat命令
- Sqlserver转mysql方法
- 第1天
- java 守护线程
- ios6下的storyboard使用详解
- 使用gdb调试程序
- 队列的基本操作
- jdbc(Oracle数据库)