Equal Row and Column Pairs LeetCode solution in Python
1# Runtime: 467 ms (Top 64.2%) | Memory: 21.54 MB (Top 44.5%)234class Solution:5def equalPairs(self, grid: List[List[int]]) -> int:6m = defaultdict(int)7cnt = 089for row in grid:10m[str(row)] += 11112for i in range(len(grid[0])):13col = []14for j in range(len(grid)):15col.append(grid[j][i])16cnt += m[str(col)]17return cnt