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.
1 parent 3d3b94d commit 1646256Copy full SHA for 1646256
C++/count-servers-that-communicate.cpp
@@ -0,0 +1,25 @@
1
+// Time: O(m * n)
2
+// Space: O(m + n)
3
+
4
+class Solution {
5
+public:
6
+ int countServers(vector<vector<int>>& grid) {
7
+ vector<int> rows(grid.size()), columns(grid[0].size());
8
+ for (int i = 0; i < grid.size(); ++i) {
9
+ for (int j = 0; j < grid[i].size(); ++j) {
10
+ if (grid[i][j]) {
11
+ ++rows[i], ++columns[j];
12
+ }
13
14
15
+ int result = 0;
16
17
18
+ if (grid[i][j] && (rows[i] > 1 || columns[j] > 1)) {
19
+ ++result;
20
21
22
23
+ return result;
24
25
+};
0 commit comments