LeetCode77——Combinations
来源:互联网 发布:mac matlab mex用法 编辑:程序博客网 时间:2024/05/16 14:22
LeetCode77——Combinations
题意:
两个数字n和k,找出所有这样的组合:
1.组合中有k个数字
2.组合是递增
3.组合中的数字是{1,2,3,....n} 的子集
为了叙述方便,假设子集为D,子集的大小为k。
那就是回溯了,对D中所有的数字进行k阶全排列,但这个全排列要排除非增序的组合。
代码:
class Solution {private: void help(int i,int n, int k,vector<int>temp,vector<vector<int>>&result){if (temp.size() == k)//k个数{result.push_back(temp);return;}if (temp.size() > 1 && temp.back() < *(temp.end()-2))//递增return;for (int index = i+1; index < n+1; index++)//i{temp.push_back(index);help(index , n, k, temp, result);//递归temp.pop_back();//一次完成要弹出}}public:vector<vector<int>> combine(int n, int k) {vector<int> temp;vector<vector<int>>result;help(0, n, k, temp, result);return result;}};
0 0
- LeetCode77——Combinations
- LeetCode77:Combinations
- LeetCode77. Combinations
- leetcode77 Combinations
- leetcode77. Combinations
- LeetCode77 Combinations
- LeetCode —— Combinations
- LeetCode——Combinations
- leetcode——Combinations
- Algorithms—77.Combinations
- leetcode 077 —— Combinations
- LeetCode题解——Combinations
- 算法系列——Combinations
- LeetCode—*组合问题Combinations
- leetcode——77——Combinations
- 8.5—暴力枚举法—Combinations
- [Leetcode77, medium] Combination
- Leetcode77: Linked List Cycle
- LightOJ 1019 Brush (V)
- 【持久化框架】SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载
- java 在MySQL中存储文件,读取文件(包括图片,word文档,excel表格,ppt,zip文件等)
- 地图染色问题(回溯法)
- lintcode:Find Minimum in Rotated Sorted Array
- LeetCode77——Combinations
- JNI中的java类参数传递
- 枚举
- Android实习一个月了
- Js event事件在IE、FF兼容性问题
- RestServer 1.1
- 通过WindowManager实现拖动悬浮框
- Fire Station
- 从零开始Android