LeetCode —— Combinations
来源:互联网 发布:淘宝刷流量软件安全吗 编辑:程序博客网 时间:2024/04/23 16:36
链接:http://leetcode.com/onlinejudge#question_77
原题:
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<int> vec; vector<vector<int> > collection; search(n, k, 1, vec, collection); return collection; } private: void search(int n, int k, int start, vector<int> &vec, vector<vector<int> > &collection) { if (k == 0) { collection.push_back(vec); return; } for (int i=start; i<=n-k+1; i++) { vec.push_back(i); search(n, k-1, i+1, vec, collection); vec.pop_back(); } }};
- LeetCode —— Combinations
- LeetCode——Combinations
- leetcode——Combinations
- leetcode 077 —— Combinations
- LeetCode题解——Combinations
- LeetCode—*组合问题Combinations
- leetcode——77——Combinations
- LeetCode——Letter Combinations of a Phone Number
- leetcode 017 —— Letter Combinations of a Phone Number
- LeetCode题解——Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number —— Leetcode
- LeetCode——17. Letter Combinations of a Phone Number
- Leetcode——17. Letter Combinations of a Phone Number
- leetcode—Letter Combinations of a Phone Number
- LeetCode: Combinations
- LeetCode: Combinations
- LeetCode Combinations
- [Leetcode] Combinations
- Windows Phone8模拟器设置
- 1096 立方数列求和
- UVa101 - The Blocks Problem
- 黑马程序员-javaIO
- 思科静态路由设置
- LeetCode —— Combinations
- Windows Phone自定义控件
- Android学习资源
- 对jQuery的事件绑定的一些思考
- 问题
- API 生成淘宝数据包 拍拍数据包 差异
- IBM与联想的基友关系
- 【leetcode】Binary Tree Maximum Path Sum
- 1097 特殊的整数数列求和