mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 01:49:41 +01:00
24 lines
601 B
C#
24 lines
601 B
C#
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;
|
||
}
|
||
}
|