Description
Submission
class Solution { public: vector<vector<int>> combine(int n, int k) { vector<vector<int>> res; vector<int> hand; backtrack(res, hand, k, n, 1); return res; } private: void backtrack(vector<vector<int>>& res, vector<int>& hand, int k, int n, int start) { if(k == 0) { res.push_back(hand); return; } for(int i = start; i < n + 1; ++i) { hand.push_back(i); backtrack(res, hand, k - 1, n, i + 1); hand.pop_back(); } } };