Skip to content

Commit ddcbf01

Browse files
add 1769
1 parent fb0aed3 commit ddcbf01

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1769|[Minimum Number of Operations to Move All Balls to Each Box](https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1769.java) ||Medium|Array, Greedy|
1112
|1768|[Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1768.java) ||Easy|String|
1213
|1765|[Map of Highest Peak](https://leetcode.com/problems/map-of-highest-peak/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1765.java) ||Medium|BFS, Graph|
1314
|1764|[Form Array by Concatenating Subarrays of Another Array](https://leetcode.com/problems/form-array-by-concatenating-subarrays-of-another-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1764.java) ||Medium|Array, Greedy|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1769 {
4+
public static class Solution1 {
5+
public int[] minOperations(String boxes) {
6+
int[] box = new int[boxes.length()];
7+
for (int i = 0; i < boxes.length(); i++) {
8+
box[i] = boxes.charAt(i) - '0';
9+
}
10+
int[] result = new int[boxes.length()];
11+
for (int i = 0; i < boxes.length(); i++) {
12+
int ops = 0;
13+
for (int j = 0; j < boxes.length(); j++) {
14+
if (i != j && box[j] == 1) {
15+
ops += Math.abs(j - i);
16+
}
17+
}
18+
result[i] = ops;
19+
}
20+
return result;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)