[LeetCode] Permutations

46. Permutations

Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
vector<vector<int>> permute(vector<int>& nums) {
sort(nums.begin(), nums.end());
vector<vector<int>> res;
do {
res.push_back(nums);
} while(next_permutation(begin(nums), end(nums)));
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2021/05/19/PS/LeetCode/permutations/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.