Leetcode 77. combination
来源:互联网 发布:去外企工作好吗 知乎 编辑:程序博客网 时间:2024/06/03 22:47
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
Note:
You are not suppose to use the library’s sort function for this problem.
click to show follow up.
class Solution {public: vector<vector<int>> combine(int n, int k) { vector<vector<int> > ret; vector<int> ans; reCombine(ret, ans, n, k); return ret; } void reCombine(vector<vector<int> >& ret, vector<int>& ans, int n, int k) { size_t sz = ans.size(); if (k == 0) { ret.push_back(ans); return; } size_t start; if (sz == 0) start = 1; else start = ans[sz - 1] + 1; for (size_t i = start; i <= n - k + 1; ++i) { ans.push_back(i); reCombine(ret, ans, n, k - 1); ans.pop_back(); } }};
阅读全文
0 0
- Leetcode 77. combination
- [Leetcode] Combination
- [Leetcode]combination
- <leetcode>Combination
- 【LeetCode】Combination
- Leetcode Combination
- LeetCode: Combination Sum
- LeetCode: Combination Sum II
- LeetCode: Combination Sum
- LeetCode: Combination Sum II
- [LeetCode]Combination Sum
- [LeetCode]Combination Sum II
- LeetCode Combination Sum
- LeetCode Combination Sum II
- [Leetcode] Combination Sum
- [Leetcode] Combination Sum II
- [LeetCode] Combination Sum
- [LeetCode] Combination Sum II
- 将带空格的字符串去掉空格.join()函数
- [阿里云服务配置]
- Android基于位置的服务小项目使用百度LBS SDK遇见的一系列问题及解决方法
- SQL中的游标
- POI大数量读取excel文件
- Leetcode 77. combination
- 1122. Hamiltonian Cycle (25)
- sublime 支持vue语法高亮
- js-----初步了解this对象
- multer+Ajax(es6版)实现免跳转上传图片
- Vue2+VueRouter2+Webpack+Axios 构建项目实战2017重制版(五)配置 Axios api 接口调用文件
- HDOJ 2547 无剑无我(求两点距离)
- matlab——NN代码(nnsetup)解析
- 20171202:方法和数组的学习