[LeetCode] 77. Combinations
来源:互联网 发布:流体力学软件fluent 编辑:程序博客网 时间:2024/06/06 01:18
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) { vector<vector<int>> res; vector<int> comb; combine(res, comb, 1, n, k); return res; }private: void combine(vector<vector<int>>& res, vector<int>& comb, int base, int n, int k) { if (k == 0) { res.push_back(comb); return; } for (int num = base; n + 1 - num >= k; num++) { comb.push_back(num); combine(res, comb, num + 1, n, k - 1); comb.pop_back(); } }};
阅读全文
0 0
- LeetCode 77. Combinations
- [LeetCode]77.Combinations
- LeetCode --- 77. Combinations
- [Leetcode] 77. Combinations
- [leetcode] 77.Combinations
- leetCode 77.Combinations (组合)
- [leetcode] 77. Combinations
- 77. Combinations LeetCode
- <LeetCode OJ> 77. Combinations
- [LeetCode]77. Combinations
- leetcode 77. Combinations
- LeetCode *** 77. Combinations
- leetcode 77. Combinations
- LeetCode 77. Combinations
- LeetCode-77.Combinations
- LeetCode 77.Combinations
- [LeetCode]problem 77. Combinations
- [LeetCode] 77. Combinations
- 前端基础学习之CSS选择器
- Integer String 的equals == 区别
- DOM基础二
- 模拟捕获SIGPIPE信号 实现TCP服务器
- LitJSON之JSON与对象间的相互映射
- [LeetCode] 77. Combinations
- java中最常用jar包
- 【dp专题1】hdu1087最大上升子段和 E
- 119. Pascal's Triangle II
- ios 限制UIButton点击频率
- C++类型转换操作符---补充(8)《Effective C++》
- extends 继承
- extjs4 grid合并列和合并行
- 【并查集】OJ_0003 A Bug