java.lang.Object
g1701_1800.s1758_minimum_changes_to_make_alternating_binary_string.Solution

public class Solution extends Object
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>&quot;010&quot;</code> is alternating, while the string <code>&quot;0100&quot;</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 = &ldquo;0100&rdquo;</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> If you change the last character to &lsquo;1&rsquo;, s will be &ldquo;0101&rdquo;, which is alternating.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;10&rdquo;</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 = &ldquo;1111&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> You need two operations to reach &ldquo;0101&rdquo; or &ldquo;1010&rdquo;.</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 Details

    • Solution

      public Solution()
  • Method Details

    • minOperations

      public int minOperations(String s)