forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1582.java
31 lines (29 loc) · 915 Bytes
/
_1582.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.fishercoder.solutions;
public class _1582 {
public static class Solution1 {
public int numSpecial(int[][] mat) {
int count = 0;
for (int i = 0; i < mat.length; i++) {
for (int j = 0; j < mat[0].length; j++) {
if (mat[i][j] == 1 && isSpecial(mat, i, j)) {
count++;
}
}
}
return count;
}
private boolean isSpecial(int[][] mat, int row, int col) {
for (int i = 0; i < mat.length; i++) {
if (i != row && mat[i][col] == 1) {
return false;
}
}
for (int j = 0; j < mat[0].length; j++) {
if (j != col && mat[row][j] == 1) {
return false;
}
}
return true;
}
}
}