Skip to content

Commit 258ccad

Browse files
committedJul 31, 2024·
add 2946
1 parent 3655f82 commit 258ccad

File tree

3 files changed

+68
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+68
-0
lines changed
 

‎paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| 2960 | [Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2960.java) | | Easy |
88
| 2956 | [Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2956.java) | | Easy |
99
| 2951 | [Find the Peaks](https://leetcode.com/problems/find-the-peaks/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2951.java) | | Easy |
10+
| 2946 | [Matrix Similarity After Cyclic Shifts](https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2946.java) | | Easy |
1011
| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2942.java) | | Easy |
1112
| 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2937.java) | | Easy |
1213
| 2932 | [Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2932.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.Arrays;
4+
5+
public class _2946 {
6+
public static class Solution1 {
7+
public boolean areSimilar(int[][] mat, int k) {
8+
int m = mat.length;
9+
int n = mat[0].length;
10+
k %= n;
11+
if (k == 0) {
12+
return true;
13+
}
14+
int[][] updated = new int[m][n];
15+
for (int i = 0; i < m; i++) {
16+
for (int j = 0; j < n; j++) {
17+
//regardless i is even or odd, it's the same formula below!
18+
updated[i][(j + k) % n] = mat[i][j];
19+
}
20+
}
21+
for (int i = 0; i < m; i++) {
22+
if (!Arrays.equals(mat[i], updated[i])) {
23+
return false;
24+
}
25+
}
26+
return true;
27+
}
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.common.utils.CommonUtils;
4+
import com.fishercoder.solutions.thirdthousand._2946;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertTrue;
9+
10+
public class _2946Test {
11+
private static _2946.Solution1 solution1;
12+
13+
@BeforeEach
14+
public void setup() {
15+
solution1 = new _2946.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
assertTrue(solution1.areSimilar(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[1,2,1,2],[5,5,5,5],[6,3,6,3]"), 2));
21+
}
22+
23+
@Test
24+
public void test2() {
25+
assertTrue(solution1.areSimilar(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[3,10,3,10,3,10,3,10],[5,8,5,8,5,8,5,8],[3,9,3,9,3,9,3,9],[3,8,3,8,3,8,3,8],[2,3,2,3,2,3,2,3]"), 2));
26+
}
27+
28+
@Test
29+
public void test3() {
30+
assertTrue(solution1.areSimilar(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[9,5,3,10],[4,7,10,7],[1,7,9,4],[8,8,1,6],[6,7,6,1],[3,1,1,8],[9,2,8,3],[1,9,7,6]"), 4));
31+
}
32+
33+
@Test
34+
public void test4() {
35+
assertTrue(solution1.areSimilar(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[9,1,8,9,2,9,1,8,9,2],[10,2,7,8,9,10,2,7,8,9],[7,6,6,9,5,7,6,6,9,5]"), 5));
36+
}
37+
38+
}

0 commit comments

Comments
 (0)
Please sign in to comment.