leetcode

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

2482.cpp (563B)


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