2380. Time Needed to Rearrange a Binary String

Updated: 2024-03-12
1 min read
[]

On This Page

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