leetcode

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

2352.cpp (433B)


      1 class Solution {
      2   public:
      3     int equalPairs(vector<vector<int>> &grid) {
      4         int n = grid.size(), res = 0;
      5         map<vector<int>, int> m;
      6         for (const auto &vec : grid)
      7             m[vec]++;
      8 
      9         for (int i = 0; i < n; i++)
     10             for (int j = 0; j < n; j++)
     11                 if (i < j) swap(grid[i][j], grid[j][i]);
     12 
     13         for (const auto &vec : grid)
     14             res += m[vec];
     15         return res;
     16     }
     17 };