leetcode

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

commit d4141c637fa4f99dd0b8487730cf5f52468d2ad6
parent 0429b82834dc197ec54949683a732805990c9c98
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Tue, 13 Jun 2023 19:46:54 +0200

Daily Problem

Diffstat:
AProblems/2352.cpp | 15+++++++++++++++
MREADME.md | 1+
2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/Problems/2352.cpp b/Problems/2352.cpp @@ -0,0 +1,15 @@ +class Solution { +public: + int equalPairs(vector<vector<int>> &grid) { + int n = grid.size(), res = 0; + map<vector<int>, int> m; + for (const auto &vec : grid) m[vec]++; + + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (i < j) swap(grid[i][j], grid[j][i]); + + for (const auto &vec : grid) res += m[vec]; + return res; + } +}; diff --git a/README.md b/README.md @@ -546,6 +546,7 @@ for solving problems. | 2336 | Medium | [Smallest Number in Infinite Set](Problems/2336.cpp) | | 2343 | Medium | [Query Kth Smallest Trimmed Number](Problems/2343.cpp) | | 2348 | Medium | [Number of Zero-Filled Subarrays](Problems/2348.cpp) | +| 2352 | Medium | [Equal Row and Column Pairs](Problems/2352.cpp) | | 2359 | Medium | [Find Closest Node to Given Two Nodes](Problems/2359.cpp) | | 2360 | Hard | [Longest Cycle in a Graph](Problems/2360.cpp) | | 2368 | Medium | [Reachable Nodes With Restrictions](Problems/2368.cpp) |