All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g1501_1600.s1529_minimum_suffix_flips.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package g1501_1600.s1529_minimum_suffix_flips

// #Medium #String #Greedy #2023_06_12_Time_200_ms_(100.00%)_Space_36.9_MB_(100.00%)

class Solution {
    fun minFlips(target: String): Int {
        var flipCount = target[0].code - 48
        var prev = target[0]
        for (ch in target.toCharArray()) {
            if (ch != prev) {
                flipCount++
                prev = ch
            }
        }
        return flipCount
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy