Minimum Changes To Make Alternating Binary String
題目說明
給定一個僅由字元0
和1
組成的字串 s。
在一次操作中,您可以將任何0
更改為1
,或是將任何1
更改為0
。
如果沒有兩個相鄰字元相等,則該字串稱為交替字串。
例如,字串010
是交替的,而字串0100
則不是。 傳回使 s 交替所需的最少操作數。
輸入
由數個0
與1
組成的字串
輸出
使字串交替的最短操作數
sample input1
0100
sample output1
1
// 如果將最後一個字元更改為1,則 s 將變為0101,即是交替的。
sample input2
10
sample output2
0
Comments