- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1769.java
23 lines (22 loc) · 749 Bytes
/
_1769.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
packagecom.fishercoder.solutions.secondthousand;
publicclass_1769 {
publicstaticclassSolution1 {
publicint[] minOperations(Stringboxes) {
int[] box = newint[boxes.length()];
for (inti = 0; i < boxes.length(); i++) {
box[i] = boxes.charAt(i) - '0';
}
int[] result = newint[boxes.length()];
for (inti = 0; i < boxes.length(); i++) {
intops = 0;
for (intj = 0; j < boxes.length(); j++) {
if (i != j && box[j] == 1) {
ops += Math.abs(j - i);
}
}
result[i] = ops;
}
returnresult;
}
}
}