Skip to content

Commit 61efdc7

Browse files
committed
Time: 0 ms (100%), Space: 9.4 MB (59.31%) - LeetHub
1 parent ff56fa2 commit 61efdc7

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
string makeLargestSpecial(string s) {
4+
int n=s.size();
5+
if(s.empty())return "";
6+
vector<string>ar;
7+
int cnt=0,init=0;
8+
for(int i=0;i<n;++i)
9+
{
10+
cnt+=(s[i]=='1')?1:-1;
11+
if(cnt==0)
12+
{
13+
string st=s.substr(init+1,i-init-1);
14+
ar.push_back("1"+makeLargestSpecial(st)+"0");
15+
init=i+1;
16+
}
17+
}
18+
sort(ar.begin(),ar.end(),greater<string>());
19+
string ans;
20+
for(auto& it:ar)ans+=it;
21+
return ans;
22+
}
23+
};

0 commit comments

Comments
 (0)