Class Solution
java.lang.Object
g1801_1900.s1864_minimum_number_of_swaps_to_make_the_binary_string_alternating.Solution
1864 - Minimum Number of Swaps to Make the Binary String Alternating.<p>Medium</p>
<p>Given a binary string <code>s</code>, return <em>the <strong>minimum</strong> number of character swaps to make it <strong>alternating</strong> , or</em> <code>-1</code> <em>if it is impossible.</em></p>
<p>The string is called <strong>alternating</strong> if no two adjacent characters are equal. For example, the strings <code>"010"</code> and <code>"1010"</code> are alternating, while the string <code>"0100"</code> is not.</p>
<p>Any two characters may be swapped, even if they are <strong>not adjacent</strong>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “111000”</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> Swap positions 1 and 4: “111000” -> “101010” The string is now alternating.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “010”</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> The string is already alternating, no swaps are needed.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “1110”</p>
<p><strong>Output:</strong> -1</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>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minSwaps
-