[AlgoExpert] Permutations

Permutations

  • Time : O(n!)
  • Space : O(n!)
1
2
3
4
5
6
7
8
9
10
11
12
#include <vector>
using namespace std;

vector<vector<int>> getPermutations(vector<int> array) {
if(array.empty()) return {};
vector<vector<int>> res;
do {
res.push_back(array);
}while(next_permutation(begin(array), end(array)));
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/05/14/PS/AlgoExpert/permutations/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.