forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
36 lines (36 loc) · 1.05 KB
/
Solution.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
32
33
34
35
36
class Solution {
public int findBlackPixel(char[][] picture, int target) {
int m = picture.length;
int n = picture[0].length;
List<Integer>[] g = new List[n];
Arrays.setAll(g, k -> new ArrayList<>());
int[] rows = new int[m];
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (picture[i][j] == 'B') {
++rows[i];
g[j].add(i);
}
}
}
int ans = 0;
for (int j = 0; j < n; ++j) {
if (g[j].isEmpty() || (rows[g[j].get(0)] != target)) {
continue;
}
int i1 = g[j].get(0);
int ok = 0;
if (g[j].size() == rows[i1]) {
ok = target;
for (int i2 : g[j]) {
if (!Arrays.equals(picture[i1], picture[i2])) {
ok = 0;
break;
}
}
}
ans += ok;
}
return ans;
}
}