1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00

java: add “1758. Minimum Changes To Make Alternating Binary String”

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2023-12-24 11:50:20 +01:00
parent 835b0208b9
commit f0e0adde9f
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,21 @@
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);
}
}