标签:style blog color os 使用 io for div cti
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].
思路:直接使用标准库函数next_permutation求解。
1 class Solution { 2 public: 3 vector<vector<int>> permute( vector<int> &num ) { 4 vector<vector<int>> permutations; 5 sort( num.begin(), num.end() ); 6 permutations.push_back( num ); 7 while( next_permutation( num.begin(), num.end() ) ) { 8 permutations.push_back( num ); 9 } 10 return permutations; 11 } 12 };
标签:style blog color os 使用 io for div cti
原文地址:http://www.cnblogs.com/moderate-fish/p/3939500.html