https://leetcode.com/problems/permutations/description/
Given a collection of distinct 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], [3,2,1] ]
https://leetcode.com/problems/permutations/discuss/
class Solution { public: vector<vector<int> > permute(vector<int> &num) { vector<vector<int> > result; //存放结果 permuteRecursive(num, 0, result); //从0开始列 return result; } void permuteRecursive(vector<int> &num, int begin, vector<vector<int> > &result) { if (begin >= num.size()) { // one permutation instance result.push_back(num); return; } for (int i = begin; i < num.size(); i++) { swap(num[begin], num[i]); permuteRecursive(num, begin + 1, result); // reset swap(num[begin], num[i]); } } };