class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串vector */ vector<string> generatePermutation(string s) { unordered_set<string> set; vector<char> path(s.length()); f2(s, 0, path, 0, set); return vector<string>(set.begin(), set.end()); } private: static void f2(const string& s, int i, vector<char>& path, int size, unordered_set<string>& set) { if (i == s.length()) { set.insert(string(path.begin(), path.begin() + size)); } else { path[size] = s[i]; // Include current character f2(s, i + 1, path, size + 1, set); // Recur with the current character included f2(s, i + 1, path, size, set); // Recur without the current character } } };