https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string/description/ Easy

Решение

class Solution {
    fun minOperations(s: String): Int {
        var cost0 = 0
        var cost1 = 0
        for (i in s.indices) {
            val c = s[i]
            if (c != (if (i % 2 == 0) '0' else '1')) cost0++
            if (c != (if (i % 2 == 0) '1' else '0')) cost1++
        }
        return minOf(cost0, cost1)
    }
}