All prompts are owned by LeetCode. To view the prompt, click the title link above.
Completed during Weekly Contest 407 (q3)
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]
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