Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit258ccad

Browse files
add 2946
1 parent3655f82 commit258ccad

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

Lines changed: 1 addition & 0 deletions
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|
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
packagecom.fishercoder.solutions.thirdthousand;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_2946 {
6+
publicstaticclassSolution1 {
7+
publicbooleanareSimilar(int[][]mat,intk) {
8+
intm =mat.length;
9+
intn =mat[0].length;
10+
k %=n;
11+
if (k ==0) {
12+
returntrue;
13+
}
14+
int[][]updated =newint[m][n];
15+
for (inti =0;i <m;i++) {
16+
for (intj =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 (inti =0;i <m;i++) {
22+
if (!Arrays.equals(mat[i],updated[i])) {
23+
returnfalse;
24+
}
25+
}
26+
returntrue;
27+
}
28+
}
29+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
packagecom.fishercoder.thirdthousand;
2+
3+
importcom.fishercoder.common.utils.CommonUtils;
4+
importcom.fishercoder.solutions.thirdthousand._2946;
5+
importorg.junit.jupiter.api.BeforeEach;
6+
importorg.junit.jupiter.api.Test;
7+
8+
importstaticorg.junit.jupiter.api.Assertions.assertTrue;
9+
10+
publicclass_2946Test {
11+
privatestatic_2946.Solution1solution1;
12+
13+
@BeforeEach
14+
publicvoidsetup() {
15+
solution1 =new_2946.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
assertTrue(solution1.areSimilar(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[1,2,1,2],[5,5,5,5],[6,3,6,3]"),2));
21+
}
22+
23+
@Test
24+
publicvoidtest2() {
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+
publicvoidtest3() {
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+
publicvoidtest4() {
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)

[8]ページ先頭

©2009-2025 Movatter.jp