We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 8e019b3 + 8928a1e commit 3660c78Copy full SHA for 3660c78
1267. Count Servers that Communicate
@@ -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
17
+ if (grid[i][j] == 1 && (rows[i] > 1 || cols[j] > 1))
18
+ ++ans;
19
20
+ return ans;
21
22
+};
0 commit comments