2380. Time Needed to Rearrange a Binary String

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2380

class Solution:
    def secondsToRemoveOccurrences(self, s: str) -> int:
        res = cnt = 0
        for c in s:
            if c == '0':
                cnt += 1
            elif cnt:
                res = max(res + 1, cnt)
        return res