题解 | #字符串的排列#
字符串的排列
http://www.nowcoder.com/practice/fe6b651b66ae47d7acce78ffdd9a96c7
方法之一next_permutation
CPP提供了内置函数next_permutation实现全排列,但需要对原数组进行排序。
class Solution {
public:
vector Permutation(string str) {
string path;
vector res;
sort(str.begin(), str.end());
do{
for(int i = 0; i < str.size(); i++){
path += str[i];
}
res.emplace_back(path);
path.erase(path.begin(), path.end());
}while(next_permutation(str.begin(), str.end()));
return res;
}
};

