Class Solution
java.lang.Object
g2301_2400.s2380_time_needed_to_rearrange_a_binary_string.Solution
2380 - Time Needed to Rearrange a Binary String.<p>Medium</p>
<p>You are given a binary string <code>s</code>. In one second, <strong>all</strong> occurrences of <code>"01"</code> are <strong>simultaneously</strong> replaced with <code>"10"</code>. This process <strong>repeats</strong> until no occurrences of <code>"01"</code> exist.</p>
<p>Return <em>the number of seconds needed to complete this process.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “0110101”</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong></p>
<p>After one second, s becomes “1011010”.</p>
<p>After another second, s becomes “1101100”.</p>
<p>After the third second, s becomes “1110100”.</p>
<p>After the fourth second, s becomes “1111000”.</p>
<p>No occurrence of “01” exists any longer, and the process needed 4 seconds to complete, so we return 4.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “11100”</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> No occurrence of “01” exists in s, and the processes needed 0 seconds to complete, so we return 0.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 1000</code></li>
<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
</ul>
<p><strong>Follow up:</strong></p>
<p>Can you solve this problem in O(n) time complexity?</p>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
secondsToRemoveOccurrences
-