2023-12-24 11:50:20 +01:00
|
|
|
class Solution {
|
2024-03-02 21:01:53 +01:00
|
|
|
public int minOperations(String s) {
|
|
|
|
int startingZero = 0;
|
|
|
|
int startingOne = 0;
|
2023-12-24 11:50:20 +01:00
|
|
|
|
2024-03-02 21:01:53 +01:00
|
|
|
for (int i = 0; i < s.length(); ++i) {
|
|
|
|
char c = s.charAt(i);
|
2023-12-24 11:50:20 +01:00
|
|
|
|
2024-03-02 21:01:53 +01:00
|
|
|
if (c != '0' + i % 2) {
|
|
|
|
++startingZero;
|
|
|
|
}
|
2023-12-24 11:50:20 +01:00
|
|
|
|
2024-03-02 21:01:53 +01:00
|
|
|
if (c != '0' + (i + 1) % 2) {
|
|
|
|
++startingOne;
|
|
|
|
}
|
2023-12-24 11:50:20 +01:00
|
|
|
}
|
2024-03-02 21:01:53 +01:00
|
|
|
|
|
|
|
return Math.min(startingZero, startingOne);
|
|
|
|
}
|
2023-12-24 11:50:20 +01:00
|
|
|
}
|