[leetcode]Combinations
2023-09-27 14:22:41 时间
class Solution { vector<vector<int>> result; public: void dfs(vector<int> &tmp, int level, int n, int k){ if(level > n){ if(tmp.size() == k){ result.push_back(tmp); } return; } dfs(tmp, level+1, n, k); tmp.push_back(level); dfs(tmp, level+1, n, k); tmp.pop_back(); } vector<vector<int> > combine(int n, int k) { // Start typing your C/C++ solution below // DO NOT write int main() function result.clear(); vector<int> tmp; dfs(tmp, 1, n, k); return result; } };
相关文章
- LeetCode_贪心算法_中等_670.最大交换
- LeetCode_位运算_简单_1684.统计一致字符串的数目
- LeetCode_单调栈_简单_496.下一个更大元素 I
- LeetCode_字符串_中等_647.回文子串
- LeetCode·每日一题·2037.使每位学生都有座位的最少移动次数·贪心
- LeetCode·每日一题·640.求解方程·模拟构造
- LeetCode-101.对称二叉树
- [LeetCode] 114. Flatten Binary Tree to Linked List 将二叉树展平为链表
- LeetCode Top Interview Questions
- [LeetCode] 527. Word Abbreviation 单词缩写
- [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合
- leetcode 394 字符串解码
- #leetcode 637二叉树的层平均值