Class Solution
java.lang.Object
g1701_1800.s1702_maximum_binary_string_after_change.Solution
1702 - Maximum Binary String After Change.<p>Medium</p>
<p>You are given a binary string <code>binary</code> consisting of only <code>0</code>’s or <code>1</code>’s. You can apply each of the following operations any number of times:</p>
<ul>
<li>Operation 1: If the number contains the substring <code>"00"</code>, you can replace it with <code>"10"</code>.
<ul>
<li>For example, <code>"00010" -> "10010</code>"</li>
</ul>
</li>
<li>Operation 2: If the number contains the substring <code>"10"</code>, you can replace it with <code>"01"</code>.
<ul>
<li>For example, <code>"00010" -> "00001"</code></li>
</ul>
</li>
</ul>
<p><em>Return the <strong>maximum binary string</strong> you can obtain after any number of operations. Binary string <code>x</code> is greater than binary string <code>y</code> if <code>x</code>’s decimal representation is greater than <code>y</code>’s decimal representation.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> binary = “000110”</p>
<p><strong>Output:</strong> “111011”</p>
<p><strong>Explanation:</strong> A valid transformation sequence can be:</p>
<p>“000110” -> “000101”</p>
<p>“000101” -> “100101”</p>
<p>“100101” -> “110101”</p>
<p>“110101” -> “110011”</p>
<p>“110011” -> “111011”</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> binary = “01”</p>
<p><strong>Output:</strong> “01”</p>
<p><strong>Explanation:</strong> “01” cannot be transformed any further.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= binary.length <= 10<sup>5</sup></code></li>
<li><code>binary</code> consist of <code>'0'</code> and <code>'1'</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maximumBinaryString
-