bumpsoo 2025-01-06 22:20:23 +09:00
parent 018bef7505
commit de3aca0d83

View file

@ -0,0 +1,21 @@
# https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box
from typing import List
class Solution:
def minOperations(self, boxes: str) -> List[int]:
l = len(boxes)
result = [0] * (l + 1)
left, right = 0, 0
for i in range(l):
if boxes[i] == "1":
result[0] += i + 1
right += 1
for i in range(l):
result[i + 1] = result[i] - right + left
if boxes[i] == "1":
right -= 1
left += 1
return result[1:]