Skip to content

Instantly share code, notes, and snippets.

@bkb181
Created June 2, 2020 06:03
Show Gist options
  • Save bkb181/e2224814d7faf51ed4bbc567905da2e8 to your computer and use it in GitHub Desktop.
Save bkb181/e2224814d7faf51ed4bbc567905da2e8 to your computer and use it in GitHub Desktop.
void permutation(string S, int n, string res)
{
if (n == 1)
{
cout << res + S << endl;
return;
}
for (int i = 0; i < n; i++)
{
permutation(S.substr(1), n - 1, res + S[0]);
rotate(S.begin(), S.begin() + 1, S.end());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment