Skip to content

Instantly share code, notes, and snippets.

@ABHIINAV12
Created November 9, 2020 02:47
Show Gist options
  • Save ABHIINAV12/e27c1274c01fd342e29e053ee58a1223 to your computer and use it in GitHub Desktop.
Save ABHIINAV12/e27c1274c01fd342e29e053ee58a1223 to your computer and use it in GitHub Desktop.
Given a collection of distinct integers, return all possible permutations.
class Solution {
public:
vector<vector<int>> permute(vector<int>& nums) {
vector<vector<int>> ret;
sort(nums.begin(),nums.end());
do{
ret.push_back(nums);
}while(next_permutation(nums.begin(),nums.end()));
return ret;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment