Created
June 13, 2018 02:07
-
-
Save ivorynoise/76562aa2d5187e2cbff5fe205f573fdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void findPermutations(vector<int>A, int i, vector<vector<int> >& all){ | |
if (i == A.size()){ | |
all.push_back(A); | |
return ; | |
} | |
vector<int> sortedCopy(A); | |
for(int pos = i; pos < A.size(); ++pos){ | |
swap(sortedCopy[i], sortedCopy[pos]); | |
A = sortedCopy; | |
findPermutations(A, i + 1, all); | |
} | |
} | |
vector<vector<int> > Solution::permute(vector<int> &A) { | |
vector<vector<int> > all; | |
sort(A.begin(), A.end()); | |
findPermutations(A, 0, all); | |
return all; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment