From a2a7dc0a3d58db8a2f0e033a261064602d4f861a Mon Sep 17 00:00:00 2001 From: pradeeptosarkar <50446690+pradeeptosarkar@users.noreply.github.com> Date: Wed, 13 Dec 2023 12:52:36 +0000 Subject: [PATCH] Sync LeetCode submission - Special Positions in a Binary Matrix (cpp) --- .../solution.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 LeetCode/problems/special_positions_in_a_binary_matrix/solution.cpp diff --git a/LeetCode/problems/special_positions_in_a_binary_matrix/solution.cpp b/LeetCode/problems/special_positions_in_a_binary_matrix/solution.cpp new file mode 100644 index 0000000..b425710 --- /dev/null +++ b/LeetCode/problems/special_positions_in_a_binary_matrix/solution.cpp @@ -0,0 +1,31 @@ +class Solution { +public: + int numSpecial(vector>& mat) { + int m = mat.size(); + int n = mat[0].size(); + vector rowCount(m, 0); + vector colCount(n, 0); + + for (int row = 0; row < m; row++) { + for (int col = 0; col < n; col++) { + if (mat[row][col] == 1) { + rowCount[row]++; + colCount[col]++; + } + } + } + + int ans = 0; + for (int row = 0; row < m; row++) { + for (int col = 0; col < n; col++) { + if (mat[row][col] == 1) { + if (rowCount[row] == 1 && colCount[col] == 1) { + ans++; + } + } + } + } + + return ans; + } +}; \ No newline at end of file