leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1267.cpp (560B)
0 class Solution { 1 public: 2 int countServers(const vector<vector<int>> &grid) { 3 const int n = grid.size(), m = grid[0].size(); 4 int row[256] = {0}, col[256] = {0}; 5 6 for (int i = 0; i < n; i++) { 7 for (int j = 0; j < m; j++) { 8 if (grid[i][j]) row[i]++, col[j]++; 9 } 10 } 11 12 int res = 0; 13 for (int i = 0; i < n; i++) { 14 for (int j = 0; j < m; j++) { 15 if (grid[i][j]) res += row[i] > 1 || col[j] > 1; 16 } 17 } 18 19 return res; 20 } 21 };