Untitled
unknown
c_cpp
5 months ago
495 B
2
Indexable
string largestMagical(string binString) { if (binString.empty()) return binString; vector<string> ans; int cnt = 0, j = 0; for (int i = 0; i < binString.size(); ++i) { cnt += binString[i] == '1' ? 1 : -1; if (cnt == 0) { ans.push_back("1" + largestMagical(binString.substr(j + 1, i - j - 1)) + "0"); j = i + 1; } } sort(ans.begin(), ans.end(), greater<string>()); return accumulate(ans.begin(), ans.end(), string{}); }
Editor is loading...
Leave a Comment