1079.cpp (573B)
1 class Solution { 2 unordered_set<string> us; 3 bool used[8] = {false}; 4 string crnt; 5 6 void rec(const string &tiles) { 7 us.insert(crnt); 8 if (crnt.size() == tiles.size()) return; 9 10 for (int i = 0; i < tiles.size(); i++) { 11 if (used[i]) continue; 12 used[i] = true; 13 crnt.push_back(tiles[i]); 14 rec(tiles); 15 crnt.pop_back(); 16 used[i] = false; 17 } 18 } 19 20 public: 21 int numTilePossibilities(const string tiles) { 22 rec(tiles); 23 return us.size() - 1; 24 } 25 };