Skip to content

Instantly share code, notes, and snippets.

@LujunWeng
Created January 21, 2019 04:06
Show Gist options
  • Save LujunWeng/75ff1eeb32a47d3850bd77d466955750 to your computer and use it in GitHub Desktop.
Save LujunWeng/75ff1eeb32a47d3850bd77d466955750 to your computer and use it in GitHub Desktop.
Permutation, swap, recursive
void doPerm(vector<int>& nums, int start,
vector<vector<int>>& collector) {
if (start == nums.size())
collector.push_back(nums);
else {
for (int i = start; i < nums.size(); ++i) {
std::swap(nums[start], nums[i]);
doPerm(nums, start+1, collector);
std::swap(nums[start], nums[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment