[leetcode]Combinations
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; } };
补充:web前端 , JavaScript ,