Minimum Number of Operations to Move All Balls to Each Box LeetCode solution in Java

1
class Solution {
2
public int[] minOperations(String boxes) {
3
int n = boxes.length();
4
int[] ans = new int[n];
5
for (int i = 0; i < n; i++) {
6
int t = 0;
7
for (int j = 0; j < n; j++) {
8
char c = boxes.charAt(j);
9
if (c == '1') t += Math.abs(i - j);
10
}
11
ans[i] = t;
12
}
13
return ans;
14
}
15
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0