8000 update 2134 · githubniraj/Leetcode@59ad48d · GitHub
[go: up one dir, main page]

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

Appearance settings

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

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 (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++;

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
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)
0