leetcode Combinations
来源:互联网 发布:网络安全技术题 编辑:程序博客网 时间:2024/06/06 13:13
此题利用递归回溯思想
代码
class Solution {public: vector<vector<int> > combine(int n, int k) { vector<vector<int> > result; if(n<k||k==0) return result; vector<int> temp; combineHelper(result, temp, n, k, 1); return result; } void combineHelper(vector<vector<int> > &result, vector<int> temp, int n, int k, int start) { if(temp.size()==k) { result.push_back(temp); return ; } for(int i = start; i <= n; ++i) { temp.push_back(i); combineHelper(result, temp, n, k, i+1); temp.pop_back(); } }};
0 0
- 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
- 【DP】UVA 111 History Grading
- 几种通信编码方式
- 关于多线程和GCD新手教程(一)
- usb-skeleton.c
- Object-c基础编程学习笔记-协议
- leetcode Combinations
- Java与C++继承中的重载,覆盖和隐藏
- group by 扩展函数之GROUPING SETS
- html小知识12
- UVa 572 油田
- git简介
- First Date
- 如何应对危机
- hnu 12948