2352. Equal Row and Column Pairs
Medium
Last updated
Medium
Last updated
Given a 0-indexed n x n
integer matrix grid
, return the number of pairs (Ri, Cj)
such that row Ri
and column Cj
are equal.
A row and column pair is considered equal if they contain the same elements in the same order (i.e. an equal array).
Example 1:
Example 2:
Constraints:
n == grid.length == grid[i].length
1 <= n <= 200
1 <= grid[i][j] <= 105
先建立 map 來儲存 相異 row 出現的次數,再與 column 進行比較和答案的加總。