Minimum Changes To Make Alternating Binary String


Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 10M

Authors:
Problem type

題目說明

給定一個僅由字元01組成的字串 s。

在一次操作中,您可以將任何0更改為1,或是將任何1更改為0

如果沒有兩個相鄰字元相等,則該字串稱為交替字串。

例如,字串010是交替的,而字串0100則不是。 傳回使 s 交替所需的最少操作數。

輸入

由數個01組成的字串

輸出

使字串交替的最短操作數

sample input1

0100

sample output1

1
// 如果將最後一個字元更改為1,則 s 將變為0101,即是交替的。

sample input2

10

sample output2

0

Comments

There are no comments at the moment.