We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a95468a commit 5507e18Copy full SHA for 5507e18
src/main/java/g1701_1800/s1769_minimum_number_of_operations_to_move_all_balls_to_each_box/Solution.java
@@ -4,31 +4,26 @@
4
5
public class Solution {
6
public int[] minOperations(String boxes) {
7
-
8
int countFromLeft = 0;
9
int countFromRight = 0;
10
int moves = 0;
11
int[] result = new int[boxes.length()];
12
13
for (char c : boxes.toCharArray()) {
14
moves += countFromLeft;
15
if (c == '1') {
16
countFromLeft++;
17
}
18
19
20
for (int i = boxes.length() - 1; i >= 0; i--) {
21
char c = boxes.charAt(i);
22
result[i] = moves;
23
24
25
countFromLeft--;
26
countFromRight++;
27
28
moves -= countFromLeft;
29
moves += countFromRight;
30
31
32
return result;
33
34
0 commit comments