Skip to content

Commit e139143

Browse files
add 3417
1 parent b7f4f26 commit e139143

3 files changed

Lines changed: 65 additions & 0 deletions

File tree

  • paginated_contents/algorithms/4th_thousand
  • src

‎paginated_contents/algorithms/4th_thousand/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
| 3438 | [Find Valid Pair of Adjacent Digits in String](https://leetcode.com/problems/find-valid-pair-of-adjacent-digits-in-string/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3438.java) | | Easy |
9898
| 3432 | [Count Partitions with Even Sum Difference](https://leetcode.com/problems/count-partitions-with-even-sum-difference/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3432.java) | | Easy |
9999
| 3423 | [Maximum Difference Between Adjacent Elements in a Circular Array](https://leetcode.com/problems/maximum-difference-between-adjacent-elements-in-a-circular-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3423.java) | | Easy |
100+
| 3417 | [Zigzag Grid Traversal With Skip](https://leetcode.com/problems/zigzag-grid-traversal-with-skip/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3417.java) | | Easy |
100101
| 3411 | [Maximum Subarray With Equal Products](https://leetcode.com/problems/maximum-subarray-with-equal-products/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3411.java) | | Easy |
101102
| 3407 | [Substring Matching Pattern](https://leetcode.com/problems/substring-matching-pattern/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3407.java) | | Easy |
102103
| 3402 | [Minimum Operations to Make Columns Strictly Increasing](https://leetcode.com/problems/minimum-operations-to-make-columns-strictly-increasing/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java) | | Easy |
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _3417 {
7+
public static class Solution1 {
8+
public List<Integer> zigzagTraversal(int[][] grid) {
9+
List<Integer> list = new ArrayList<>();
10+
int m = grid.length;
11+
int n = grid[0].length;
12+
boolean leftToRight = true;
13+
int skip = 0;
14+
for (int i = 0; i < m; i++) {
15+
if (leftToRight) {
16+
for (int j = 0; j < n; j++) {
17+
if (skip == 0) {
18+
list.add(grid[i][j]);
19+
skip++;
20+
} else {
21+
skip--;
22+
}
23+
}
24+
} else {
25+
for (int j = n - 1; j >= 0; j--) {
26+
if (skip == 0) {
27+
list.add(grid[i][j]);
28+
skip++;
29+
} else {
30+
skip--;
31+
}
32+
}
33+
}
34+
leftToRight = !leftToRight;
35+
}
36+
return list;
37+
}
38+
}
39+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fishercoder.fourththousand;
2+
3+
import com.fishercoder.common.utils.CommonUtils;
4+
import com.fishercoder.solutions.fourththousand._3417;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.util.Arrays;
9+
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
12+
public class _3417Test {
13+
private _3417.Solution1 solution1;
14+
15+
@BeforeEach
16+
public void setup() {
17+
solution1 = new _3417.Solution1();
18+
}
19+
20+
@Test
21+
public void test1() {
22+
assertEquals(
23+
Arrays.asList(2, 1, 2), solution1.zigzagTraversal(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[2,1],[2,1],[2,1]")));
24+
}
25+
}

0 commit comments

Comments
 (0)