1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/java/minimum-changes-to-make-alternating-binary-string.java
Matej Focko 48eae7f00b
chore: run pre-commit
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-19 07:12:37 +01:00

20 lines
441 B
Java

class Solution {
public int minOperations(String s) {
int startingZero = 0;
int startingOne = 0;
for (int i = 0; i < s.length(); ++i) {
char c = s.charAt(i);
if (c != '0' + i % 2) {
++startingZero;
}
if (c != '0' + (i + 1) % 2) {
++startingOne;
}
}
return Math.min(startingZero, startingOne);
}
}