From 8928a1e6f0813d75c13ecc8cb393ad851c35ae66 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Fri, 24 Jan 2025 02:37:44 +0530 Subject: [PATCH] Create 1267. Count Servers that Communicate --- 1267. Count Servers that Communicate | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 1267. Count Servers that Communicate diff --git a/1267. Count Servers that Communicate b/1267. Count Servers that Communicate new file mode 100644 index 0000000..d60a925 --- /dev/null +++ b/1267. Count Servers that Communicate @@ -0,0 +1,22 @@ +class Solution { + public: + int countServers(vector>& grid) { + const int m = grid.size(); + const int n = grid[0].size(); + int ans = 0; + vector rows(m); + vector cols(n); + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + if (grid[i][j] == 1) { + ++rows[i]; + ++cols[j]; + } + for (int i = 0; i < m; ++i){ + for (int j = 0; j < n; ++j) + if (grid[i][j] == 1 && (rows[i] > 1 || cols[j] > 1)) + ++ans; + } + return ans; + } +};