-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1267.cpp
More file actions
26 lines (26 loc) · 719 Bytes
/
1267.cpp
File metadata and controls
26 lines (26 loc) · 719 Bytes
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
class Solution {
public:
int countServers(vector<vector<int>>& grid) {
unordered_map<int, int> rowCnt;
unordered_map<int, int> colCnt;
int m = grid.size();
int n = grid[0].size();
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (grid[i][j] == 1) {
rowCnt[i]++;
colCnt[j]++;
}
}
}
int res = 0;
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (grid[i][j] == 1) {
if (rowCnt[i] >= 2 || colCnt[j] >= 2) res++;
}
}
}
return res;
}
};