Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitddcbf01

Browse files
add 1769
1 parentfb0aed3 commitddcbf01

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+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1769 {
4+
publicstaticclassSolution1 {
5+
publicint[]minOperations(Stringboxes) {
6+
int[]box =newint[boxes.length()];
7+
for (inti =0;i <boxes.length();i++) {
8+
box[i] =boxes.charAt(i) -'0';
9+
}
10+
int[]result =newint[boxes.length()];
11+
for (inti =0;i <boxes.length();i++) {
12+
intops =0;
13+
for (intj =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+
returnresult;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp