First, write your own. . 17% of the time, space 100%, which is set to re-do the results?
set<string> res; vector<string> temp; vector<bool> ok; void back(string s) { for (int i = 0; i < temp.size(); i++) { if (ok[i]) { ok[i] = false; s += temp[i]; res.insert(s); back(s); ok[i] = true; s.pop_back(); } } } int numTilePossibilities(string tiles) { for (int i = 0; i < tiles.size(); i++) { temp.push_back(tiles.substr(i, 1)); } for (int i = 0; i < tiles.size(); i++) ok.push_back(true); string s=""; back(s); return res.size(); }
Second, the problem solution
If nothing particularly good algorithm. . Well, look at what it is tomorrow dictionary tree. .