cs: add “2352. Equal Row and Column Pairs”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
87b1174f4c
commit
34acc09b98
1 changed files with 24 additions and 0 deletions
24
cs/equal-row-and-column-pairs.cs
Normal file
24
cs/equal-row-and-column-pairs.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue