Class Solution
java.lang.Object
g1701_1800.s1758_minimum_changes_to_make_alternating_binary_string.Solution
1758 - Minimum Changes To Make Alternating Binary String.<p>Easy</p>
<p>You are given a string <code>s</code> consisting only of the characters <code>'0'</code> and <code>'1'</code>. In one operation, you can change any <code>'0'</code> to <code>'1'</code> or vice versa.</p>
<p>The string is called alternating if no two adjacent characters are equal. For example, the string <code>"010"</code> is alternating, while the string <code>"0100"</code> is not.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed to make</em> <code>s</code> <em>alternating</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “0100”</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> If you change the last character to ‘1’, s will be “0101”, which is alternating.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “10”</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> s is already alternating.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “1111”</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> You need two operations to reach “0101” or “1010”.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 10<sup>4</sup></code></li>
<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minOperations
-