#3228

Maximum Number of Operations to Move Ones to the End

specialist · 605 · lc medium +29 · premium · 67.2% accepted · 531 likes · top 73%

Description

You are given binary string s. Repeat any number of times: choose index i where s[i] == '1' and s[i + 1] == '0', then shift s[i] right until it reaches the end or another '1'.

Return the maximum number of such operations.

Code

1
2
3