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

Commit59ad48d

Browse files
update 2134
1 parent0f9beff commit59ad48d

File tree

3 files changed

+11
-6
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+11
-6
lines changed

‎paginated_contents/algorithms/3rd_thousand/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
| 2139|[Minimum Moves to Reach Target Score](https://leetcode.com/problems/minimum-moves-to-reach-target-score/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2139.java)|| Medium||
214214
| 2138|[Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2138.java)|| Easy||
215215
| 2135|[Count Words Obtained After Adding a Letter](https://leetcode.com/problems/count-words-obtained-after-adding-a-letter/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2135.java)|| Medium||
216-
| 2134|[Minimum Swaps to Group All 1's Together II](https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together-ii/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2134.java)|| Medium||
216+
| 2134 |[Minimum Swaps to Group All 1's Together II](https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together-ii/) |[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2134.java) || Medium |Array, Sliding Window
217217
| 2133|[Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2133.java)|| Easy||
218218
| 2130|[Maximum Twin Sum of a Linked List](https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2130.java)|| Medium||
219219
| 2129|[Capitalize the Title](https://leetcode.com/problems/capitalize-the-title/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2129.java)|| Easy||

‎src/main/java/com/fishercoder/solutions/thirdthousand/_2134.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ public int minSwaps(int[] nums) {
1616
ones +=num;
1717
list.add(num);
1818
}
19+
//add it again to simulate the circular list
1920
for (intnum :nums) {
2021
list.add(num);
2122
}
2223
intminSwaps =nums.length;
2324
intzeroes =0;
25+
//as long as the size of the sliding window is smaller than 1s' count, we keep moving right pointer to the right
26+
//as soon as the size of the sliding window is equal to 1s' count, we take the 0s count in this window against minSwaps to update it if possible
27+
//then if the size of the sliding window is greater than 1s' count, we move the left pointer to the right
28+
//One caveat: you don't really need to make the swaps to solve this problem, just counting the numbers is enough
2429
for (intleft =0,right =0;right <list.size();right++) {
2530
if (list.get(right) ==0) {
2631
zeroes++;

‎src/test/java/com/fishercoder/thirdthousand/_2134Test.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
packagecom.fishercoder.thirdthousand;
22

33
importcom.fishercoder.solutions.thirdthousand._2134;
4-
importorg.junit.BeforeClass;
5-
importorg.junit.Test;
4+
importorg.junit.jupiter.api.BeforeEach;
5+
importorg.junit.jupiter.api.Test;
66

7-
importstaticorg.junit.Assert.assertEquals;
7+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
88

99
publicclass_2134Test {
1010
privatestatic_2134.Solution1solution1;
1111
privatestaticint[]nums;
1212

13-
@BeforeClass
14-
publicstaticvoidsetup() {
13+
@BeforeEach
14+
publicvoidsetup() {
1515
solution1 =new_2134.Solution1();
1616
}
1717

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp