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

Commit3ef6e92

Browse files
add 1582
1 parent8190b30 commit3ef6e92

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1582|[Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1582.java)||Array|Easy|
1112
|1576|[Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1576.java)|[:tv:](https://youtu.be/SJBDLYqrIsM)|String|Easy|
1213
|1574|[Shortest Subarray to be Removed to Make Array Sorted](https://leetcode.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1574.java)||Array, Binary Search|Medium|
1314
|1572|[Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1572.java)||Array|Easy|
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1582 {
4+
publicstaticclassSolution1 {
5+
publicintnumSpecial(int[][]mat) {
6+
intcount =0;
7+
for (inti =0;i <mat.length;i++) {
8+
for (intj =0;j <mat[0].length;j++) {
9+
if (mat[i][j] ==1 &&isSpecial(mat,i,j)) {
10+
count++;
11+
}
12+
}
13+
}
14+
returncount;
15+
}
16+
17+
privatebooleanisSpecial(int[][]mat,introw,intcol) {
18+
for (inti =0;i <mat.length;i++) {
19+
if (i !=row &&mat[i][col] ==1) {
20+
returnfalse;
21+
}
22+
}
23+
for (intj =0;j <mat[0].length;j++) {
24+
if (j !=col &&mat[row][j] ==1) {
25+
returnfalse;
26+
}
27+
}
28+
returntrue;
29+
}
30+
}
31+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1582;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticjunit.framework.TestCase.assertEquals;
8+
9+
publicclass_1582Test {
10+
privatestatic_1582.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1582.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(3,solution1.numSpecial(newint[][]{
20+
{0,0,0,0,0},
21+
{1,0,0,0,0},
22+
{0,1,0,0,0},
23+
{0,0,1,0,0},
24+
{0,0,0,1,1}
25+
}));
26+
}
27+
28+
@Test
29+
publicvoidtest2() {
30+
assertEquals(2,solution1.numSpecial(newint[][]{
31+
{0,0,0,1},
32+
{1,0,0,0},
33+
{0,1,1,0},
34+
{0,0,0,0}
35+
}));
36+
}
37+
38+
@Test
39+
publicvoidtest3() {
40+
assertEquals(3,solution1.numSpecial(newint[][]{
41+
{1,0,0},
42+
{0,1,0},
43+
{0,0,1}
44+
}));
45+
}
46+
47+
@Test
48+
publicvoidtest4() {
49+
assertEquals(1,solution1.numSpecial(newint[][]{
50+
{1,0,0},
51+
{0,0,1},
52+
{1,0,0}
53+
}));
54+
}
55+
56+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp