1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00
LeetCode/cs/equal-row-and-column-pairs.cs
Matej Focko 34acc09b98
cs: add “2352. Equal Row and Column Pairs”
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-01-07 13:06:12 +01:00

24 lines
601 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

public class Solution {
public int EqualPairs(int[][] grid) {
var count = 0;
var n = grid.Length;
// Check each row r against each column c.
for (var r = 0; r < n; ++r) {
for (var c = 0; c < n; ++c) {
var match = true;
for (var i = 0; i < n; ++i) {
if (grid[r][i] != grid[i][c]) {
match = false;
break;
}
}
count += match ? 1 : 0;
}
}
return count;
}
}