Given a collection of numbers, return all possible permutations.
For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2],
and [3,2,1].
全排列,从全体元素中挑一个,放在第一个位置。
在从剩下的元素中,放在第二个位置。
在从剩下的元素中,放在第三个位置。
。。。。。。
此算法,利用交换,将已经被选择的元素交换到指定位置。右边则是剩下待选的元素。
class Solution {
public:
vector<vector<int> > permute(vector<int> &num) {
......
阅读全文