-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (38 loc) · 1009 Bytes
/
main.cpp
File metadata and controls
41 lines (38 loc) · 1009 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
int countServers(vector<vector<int>>& grid)
{
vector<int> row_count(grid.size(), 0);
vector<int> col_count(grid[0].size(), 0);
for (int i = 0; i < (int)grid.size(); ++i)
{
for (int j = 0; j < (int)grid[0].size(); ++j)
{
if (grid[i][j] == 1)
{
row_count[i]++;
col_count[j]++;
}
}
}
int counter = 0;
for (int i = 0; i < (int)grid.size(); ++i)
{
for (int j = 0; j < (int)grid[0].size(); ++j)
{
if (grid[i][j] == 1 && (row_count[i] > 1 || col_count[j] > 1))
counter++;
}
}
return counter;
}
};
int main()
{
vector<vector<int>> grid = {{1,1,0,0}, {0,0,1,0}, {0,0,1,0}, {0,0,0,1}};
cout << Solution().countServers(grid) << '\n';
return 0;
}