Untitled
unknown
c_cpp
a year ago
495 B
4
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