From 34acc09b987bd5bcb616d4b14fbba369a70df54c Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sun, 7 Jan 2024 13:06:12 +0100 Subject: [PATCH] =?UTF-8?q?cs:=20add=20=E2=80=9C2352.=20Equal=20Row=20and?= =?UTF-8?q?=20Column=20Pairs=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- cs/equal-row-and-column-pairs.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 cs/equal-row-and-column-pairs.cs diff --git a/cs/equal-row-and-column-pairs.cs b/cs/equal-row-and-column-pairs.cs new file mode 100644 index 0000000..c172bd9 --- /dev/null +++ b/cs/equal-row-and-column-pairs.cs @@ -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; + } +}