LeetCode | Permutations

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].

 1 vector<vector<int> > permute(vector<int> &num) {
 2     vector<vector<int> > result;
 3     if (num.size() == 0) return result;
 4 
 5     std::sort(num.begin(), num.end());
 6     do {
 7         result.push_back(num);
 8     } while (std::next_permutation(num.begin(), num.end()));
 9     return result;        
10 }
原文地址:https://www.cnblogs.com/linyx/p/3650113.html