- Given a collection of numbers, return all possible permutations.
- Given a collection of numbers that might contain duplicates, return all possible unique permutations.
- The set [1,2,3,…,n] contains a total of n! unique permutations. give n and k, return the kth permutation sequence.
- Given a set of distinct integers, S, return all possible subsets.
- Given a collection of integers that might contain duplicates, S, return all possible subsets.
First take a look at the first problem. permutations without duplicates.
The function should like
void permutation(vector &num, int index, vector<int> &tmp, vector<vector<int> > &res)
What it does is to take the index of num from 0 to n-1, iteratively swap index element with the element after it, then recursively call the function itself on index+1.
pseudo code:
void permutation(vector &num, int index, vector<int> &tmp, vector<vector<int> > &res){
}
The function should like
void permutation(vector
pseudo code:
void permutation(vector
}
No comments:
Post a Comment