MCPcopy Create free account
hub / github.com/chaharnishant11/CodeIn10DSA / Solution

Class Solution

Recursion/Homework/permutations.cpp:1–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2public:
3 vector<vector<int>> ans;
4 void helper(vector <int>& nums, int i){
5 if (i==nums.size()){ // Base Case
6 ans.push_back(nums);
7 return;
8 }
9 for (int j=i;j<nums.size();j++){
10 swap(nums[i],nums[j]);
11 helper(nums,i+1);
12 // backtrack
13 swap(nums[i],nums[j]);
14 }
15 return;
16
17 }
18 vector<vector<int>> permute(vector<int>& nums) {
19 helper(nums,0);
20 return ans;
21 }
22};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected