leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1267.cpp (560B)


      1 class Solution {
      2   public:
      3     int countServers(const vector<vector<int>> &grid) {
      4         const int n = grid.size(), m = grid[0].size();
      5         int row[256] = {0}, col[256] = {0};
      6 
      7         for (int i = 0; i < n; i++) {
      8             for (int j = 0; j < m; j++) {
      9                 if (grid[i][j]) row[i]++, col[j]++;
     10             }
     11         }
     12 
     13         int res = 0;
     14         for (int i = 0; i < n; i++) {
     15             for (int j = 0; j < m; j++) {
     16                 if (grid[i][j]) res += row[i] > 1 || col[j] > 1;
     17             }
     18         }
     19 
     20         return res;
     21     }
     22 };