Skip to content

Commit 3660c78

Browse files
authored
Create 1267. Count Servers that Communicate (#695)
2 parents 8e019b3 + 8928a1e commit 3660c78

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

1267. Count Servers that Communicate

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int countServers(vector<vector<int>>& grid) {
4+
const int m = grid.size();
5+
const int n = grid[0].size();
6+
int ans = 0;
7+
vector<int> rows(m);
8+
vector<int> cols(n);
9+
for (int i = 0; i < m; ++i)
10+
for (int j = 0; j < n; ++j)
11+
if (grid[i][j] == 1) {
12+
++rows[i];
13+
++cols[j];
14+
}
15+
for (int i = 0; i < m; ++i){
16+
for (int j = 0; j < n; ++j)
17+
if (grid[i][j] == 1 && (rows[i] > 1 || cols[j] > 1))
18+
++ans;
19+
}
20+
return ans;
21+
}
22+
};

0 commit comments

Comments
 (0)