Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 1.27 KB

_3228. Maximum Number of Operations to Move Ones to the End.md

File metadata and controls

57 lines (42 loc) · 1.27 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Completed during Weekly Contest 407 (q3)

Back to top


First completed : July 21, 2024

Last updated : July 21, 2024


Related Topics : String, Greedy, Counting

Acceptance Rate : 54.16 %


####Notes

    Move:
        Choose any index not the last index
        Must be pair of chars [1, 0]


Solutions

Python

class Solution:
    def maxOperations(self, s: str) -> int:
        counter = 0
        onesToLeft = 0
        prev = -1

        for curr in s : 
            if curr == '1' :
                onesToLeft += 1
                prev = '1'
            elif prev == '1':
                counter += onesToLeft
                prev = '0'
            else :
                prev = '0'

        return counter