Re: [閒聊] 每日LeetCode

作者: Rushia (みけねこ的鼻屎)   2023-06-13 15:23:48
https://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:
作者: DDFox (冒險者兼清潔工)   2023-06-13 15:25:00
大師
作者: wwndbk (黑人問號)   2023-06-13 15:25:00
大師
作者: JIWP (JIWP)   2023-06-13 15:44:00
大師
作者: pandix (麵包屌)   2023-06-13 16:15:00
用hash應該可以到O(n^2)

Links booklink

Contact Us: admin [ a t ] ucptt.com