Skip to content

Commit 5ef7c6b

Browse files
add 3643
1 parent e9b2f8f commit 5ef7c6b

3 files changed

Lines changed: 52 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
@@ -69,6 +69,7 @@
6969
| 3668 | [Restore Finishing Order](https://leetcode.com/problems/restore-finishing-order/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3668.java) | | Easy |
7070
| 3663 | [Find The Least Frequent Digit](https://leetcode.com/problems/find-the-least-frequent-digit/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3663.java) | | Easy |
7171
| 3662 | [Filter Characters by Frequency](https://leetcode.com/problems/filter-characters-by-frequency/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3662.java) | | Easy |
72+
| 3643 | [Flip Square Submatrix Vertically](https://leetcode.com/problems/flip-square-submatrix-vertically/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3643.java) | | Easy |
7273
| 3622 | [Check Divisibility by Digit Sum and Product](https://leetcode.com/problems/check-divisibility-by-digit-sum-and-product/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3622.java) | | Easy |
7374
| 3608 | [Minimum Time for K Connected Components](https://leetcode.com/problems/minimum-time-for-k-connected-components/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3608.java) | | Medium | UnionFind
7475
| 3606 | [Coupon Code Validator](https://leetcode.com/problems/coupon-code-validator/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3606.java) | | Easy |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
public class _3643 {
4+
public static class Solution1 {
5+
public int[][] reverseSubmatrix(int[][] grid, int x, int y, int k) {
6+
int top = x;
7+
int bottom = x + k - 1;
8+
int rightBoundary = y + k - 1;
9+
while (top < bottom) {
10+
int left = y;
11+
while (left <= rightBoundary) {
12+
int temp = grid[top][left];
13+
grid[top][left] = grid[bottom][left];
14+
grid[bottom][left] = temp;
15+
left++;
16+
}
17+
top++;
18+
bottom--;
19+
}
20+
return grid;
21+
}
22+
}
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fishercoder.fourththousand;
2+
3+
import com.fishercoder.common.utils.CommonUtils;
4+
import com.fishercoder.solutions.fourththousand._3643;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
9+
10+
public class _3643Test {
11+
private _3643.Solution1 solution1;
12+
13+
@BeforeEach
14+
public void setup() {
15+
solution1 = new _3643.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
assertArrayEquals((CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[1,2,3,4],[13,14,15,8],[9,10,11,12],[5,6,7,16]")), solution1.reverseSubmatrix(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]"), 1, 0, 3));
21+
}
22+
23+
@Test
24+
public void test2() {
25+
assertArrayEquals((CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[11,15,18,6],[19,19,4,15],[2,14,11,20],[14,3,18,16]")), solution1.reverseSubmatrix(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[14,3,18,16],[2,14,11,20],[19,19,4,15],[11,15,18,6]"), 0, 0, 4));
26+
}
27+
28+
}

0 commit comments

Comments
 (0)