|
| 1 | +<h2><a href="https://leetcode.com/problems/equal-row-and-column-pairs">2352. Equal Row and Column Pairs</a></h2><h3>Medium</h3><hr><p>Given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>, <em>return the number of pairs </em><code>(r<sub>i</sub>, c<sub>j</sub>)</code><em> such that row </em><code>r<sub>i</sub></code><em> and column </em><code>c<sub>j</sub></code><em> are equal</em>.</p> |
| 2 | + |
| 3 | +<p>A row and column pair is considered equal if they contain the same elements in the same order (i.e., an equal array).</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | +<img alt="" src="https://assets.leetcode.com/uploads/2022/06/01/ex1.jpg" style="width: 150px; height: 153px;" /> |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> grid = [[3,2,1],[1,7,6],[2,7,7]] |
| 10 | +<strong>Output:</strong> 1 |
| 11 | +<strong>Explanation:</strong> There is 1 equal row and column pair: |
| 12 | +- (Row 2, Column 1): [2,7,7] |
| 13 | +</pre> |
| 14 | + |
| 15 | +<p><strong class="example">Example 2:</strong></p> |
| 16 | +<img alt="" src="https://assets.leetcode.com/uploads/2022/06/01/ex2.jpg" style="width: 200px; height: 209px;" /> |
| 17 | +<pre> |
| 18 | +<strong>Input:</strong> grid = [[3,1,2,2],[1,4,4,5],[2,4,2,2],[2,4,2,2]] |
| 19 | +<strong>Output:</strong> 3 |
| 20 | +<strong>Explanation:</strong> There are 3 equal row and column pairs: |
| 21 | +- (Row 0, Column 0): [3,1,2,2] |
| 22 | +- (Row 2, Column 2): [2,4,2,2] |
| 23 | +- (Row 3, Column 2): [2,4,2,2] |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p> </p> |
| 27 | +<p><strong>Constraints:</strong></p> |
| 28 | + |
| 29 | +<ul> |
| 30 | + <li><code>n == grid.length == grid[i].length</code></li> |
| 31 | + <li><code>1 <= n <= 200</code></li> |
| 32 | + <li><code>1 <= grid[i][j] <= 10<sup>5</sup></code></li> |
| 33 | +</ul> |
0 commit comments