Posted on 2023-06-13 18:11
Uriel 阅读(44)
评论(0) 编辑 收藏 引用 所属分类:
闲来无事重切Leet Code 、
大水题
一个数字组成的二维矩阵,问有几个行列pair是所有元素都相同的(顺序也要相同),将矩阵转置再逐行对比
1 #2352
2 #Runtime: 667 ms (Beats 25%)
3 #Memory: 18 MB (Beats 22.98%)
4
5 class Solution(object):
6 def equalPairs(self, grid):
7 """
8 :type grid: List[List[int]]
9 :rtype: int
10 """
11 l = len(grid)
12 ans = 0
13 grid_trans = [[0] * l for _ in range(l)]
14 for i in range(l):
15 for j in range(l):
16 grid_trans[i][j] = grid[j][i]
17 for i in grid:
18 for j in grid_trans:
19 if i == j:
20 ans += 1
21 return ans