diff --git a/Combinations.cpp b/Combinations.cpp new file mode 100644 index 0000000..bede220 --- /dev/null +++ b/Combinations.cpp @@ -0,0 +1,35 @@ +class Solution { +public: + vector> combine(int n, int k) { + vector> ans; + vector nums; + vector comb; + + for(int i=1;i<=n;i++) + { + nums.push_back(i); + } + + combine(k,0,ans,nums,comb); + + return ans; + } + + void combine(int k, int idx,vector> &ans, vector &nums, vector &comb) + { + if(comb.size()==k) + { + ans.push_back(comb); + return; + } + + for(int i=idx;i