1864. Minimum Number of Swaps to Make the Binary String Alternating
https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-binary-string-alternating
Description
Given a binary string s
, return the minimum number of character swaps to make it alternating, or -1
if it is impossible.
The string is called alternating if no two adjacent characters are equal. For example, the strings "010"
and "1010"
are alternating, while the string "0100"
is not.
Any two characters may be swapped, even if they are not adjacent.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= s.length <= 1000
s[i]
is either'0'
or'1'
.
ac
Last updated