Skip to content

Commit 59ad48d

Browse files
update 2134
1 parent 0f9beff commit 59ad48d

File tree

3 files changed

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

3 files changed

+11
-6
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1-1
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 ||

Diff for: src/main/java/com/fishercoder/solutions/thirdthousand/_2134.java

+5
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 (int num : nums) {
2021
list.add(num);
2122
}
2223
int minSwaps = nums.length;
2324
int zeroes = 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 (int left = 0, right = 0; right < list.size(); right++) {
2530
if (list.get(right) == 0) {
2631
zeroes++;

Diff for: src/test/java/com/fishercoder/thirdthousand/_2134Test.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package com.fishercoder.thirdthousand;
22

33
import com.fishercoder.solutions.thirdthousand._2134;
4-
import org.junit.BeforeClass;
5-
import org.junit.Test;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
66

7-
import static org.junit.Assert.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
88

99
public class _2134Test {
1010
private static _2134.Solution1 solution1;
1111
private static int[] nums;
1212

13-
@BeforeClass
14-
public static void setup() {
13+
@BeforeEach
14+
public void setup() {
1515
solution1 = new _2134.Solution1();
1616
}
1717

0 commit comments

Comments
 (0)