You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
= 1769. Minimum Number of Operations to Move All Balls to Each Box
2
+
= 1769. 移动所有球到每个盒子所需的最小操作数
3
3
4
-
{leetcode}/problems/minimum-number-of-operations-to-move-all-balls-to-each-box/[LeetCode - 1769. Minimum Number of Operations to Move All Balls to Each Box ^]
You have `n`boxes. You are given a binary string `boxes` of length `n`, where`boxes[i]`is`'0'`if the `i^th^` box is *empty*, and `'1'`if it contains *one* ball.
In one operation, you can move *one* ball from a box to an adjacent box. Box `i`is adjacent to box `j`if`abs(i - j) == 1`. Note that after doing so, there may be more than one ball in some boxes.
Each`answer[i]`is calculated considering the *initial* state of the boxes.
12
+
每个`answer[i]`都需要根据盒子的 *初始状态* 进行计算。
13
13
14
-
15
-
*Example 1:*
14
+
*示例 1:*
16
15
17
-
[subs="verbatim,quotes"]
18
-
----
19
-
*Input:* boxes = "110"
20
-
*Output:* [1,1,3]
21
-
*Explanation:* The answer for each box is as follows:
22
-
1) First box: you will have to move one ball from the second box to the first box in one operation.
23
-
2) Second box: you will have to move one ball from the first box to the second box in one operation.
24
-
3) Third box: you will have to move one ball from the first box to the third box in two operations, and move one ball from the second box to the third box in one operation.
0 commit comments