-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
24 lines (24 loc) · 783 Bytes
/
Solution.cs
File metadata and controls
24 lines (24 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class Solution
{
public string MakeLargestSpecial(string s)
{
int n = s.Length;
List<string> specialSubstring = [];
int balanceCount = 0;
int startIndex = 0;
for (int i = 0; i < n; i++)
{
if (s[i] == '1') balanceCount++;
else balanceCount--;
if (balanceCount == 0)
{
string innerSubstring = s[(startIndex + 1)..i];
innerSubstring = MakeLargestSpecial(innerSubstring);
specialSubstring.Add("1" + innerSubstring + "0");
startIndex = i + 1;
}
}
specialSubstring.Sort((a, b) => string.Compare(b, a, StringComparison.Ordinal));
return string.Join("", specialSubstring);
}
}