排列组合算法之排列算法 字符串形势 C++ 小米nlp面试题
void swap(char& a, char& b){
char temp = a;
a = b;
b = temp;
}
void pai(string& str, int start, int end, vector<string>& res){
if(start == end){
string st = str;
res.emplace_back(st);
}
for(int i = start; i < end; i++){
swap(str[start], str[i]);
pai(str, start + 1, end, res);
swap(str[i], str[start]);
}
}
int test_perm(){
string str = "abcde";
vector<string> res;
pai(str, 0, (int)str.size(), res);
return 0;
}