1593.cpp (467B)
1 class Solution { 2 unordered_set<string> seen; 3 4 public: 5 int maxUniqueSplit(const string &s, int idx = 0) { 6 if (idx == size(s)) return size(seen); 7 8 int res = 0; 9 string crnt; 10 for (int i = idx; i < size(s); i++) { 11 auto it = seen.emplace(crnt += s[i]); 12 if (!it.second) continue; 13 res = max(res, maxUniqueSplit(s, i + 1)); 14 seen.erase(it.first); 15 } 16 17 return res; 18 } 19 };