C++简单代码/set去重/剪枝/追溯法/10行:
class Solution { public: set<string> res; //去重 vector<string> Permutation(string str) { if (str.empty()) return {}; string s; cutdown (str, s); return vector<string> (res.begin(), res.end()); } void cutdown(string str, string s) { if (str.size() == 0) res.insert(s); for (int i = 0; i < str.size(); i ++) { string temp = str; cutdown(temp.erase(i, 1), s + str[i]); } } };