题解 | #字符串的排列# 究极简单版
字符串的排列
https://www.nowcoder.com/practice/fe6b651b66ae47d7acce78ffdd9a96c7
#include <string> class Solution { public: void setinto( set<string> &tem, string& str, int n){ if (n == str.size() - 1) { tem.insert(str); return; } for (int i = n; i < str.size(); i++) { wswap(str[n], str[i]); setinto( tem, str, n + 1); wswap(str[n], str[i]); } } void wswap(char& a, char& b) { char temp = b; b = a; a = temp; } vector<string> Permutation(string str) { vector<string> res; set<string> tem; //sort(str.begin(),str.end()); setinto(tem, str, 0); for( set<string>::iterator it = tem.begin() ;it!= tem.end();it++){ res.push_back(*it); } return res; } };