楼主:
Rushia (みけねこ的鼻屎)
2023-06-13 15:23:48https://leetcode.com/problems/equal-row-and-column-pairs/description/
2352. Equal Row and Column Pairs
给定一个矩阵grid,判断有几个完全相等的一对行列,例如:
[1,2,3] 和 [1 两个相等。
,2
,3]
Example 1:
https://assets.leetcode.com/uploads/2022/06/01/ex1.jpg
Input: grid = [[3,2,1],[1,7,6],[2,7,7]]
Output: 1
Explanation: There is 1 equal row and column pair:
- (Row 2, Column 1): [2,7,7]
Example 2:
https://assets.leetcode.com/uploads/2022/06/01/ex2.jpg
Input: grid = [[3,1,2,2],[1,4,4,5],[2,4,2,2],[2,4,2,2]]
Output: 3
Explanation: There are 3 equal row and column pairs:
- (Row 0, Column 0): [3,1,2,2]
- (Row 2, Column 2): [2,4,2,2]
- (Row 3, Column 2): [2,4,2,2]
思路:
1.把每一行和每一列的每个元素直接比较是否相等并计数。
Java Code: