leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 4726890803716047d9cc32ac6436a787b13b59f3
parent a9cf62ae5201b0d4f8dd5a2727719a112fcbe30c
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri, 26 Jul 2024 18:21:57 +0200

1 Random Problem

Diffstat:
AProblems/3212.cpp | 19+++++++++++++++++++
MREADME.md | 1+
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/Problems/3212.cpp b/Problems/3212.cpp @@ -0,0 +1,19 @@ +class Solution { + public: + int numberOfSubmatrices(const vector<vector<char>> &grid) const { + const int n = size(grid), m = size(grid[0]); + vector<vector<int>> x(n + 1, vector(m + 1, 0)); + vector<vector<int>> y(n + 1, vector(m + 1, 0)); + int res = 0; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + x[i][j] = x[i - 1][j] + x[i][j - 1] - x[i - 1][j - 1] + (grid[i - 1][j - 1] == 'X'); + y[i][j] = y[i - 1][j] + y[i][j - 1] - y[i - 1][j - 1] + (grid[i - 1][j - 1] == 'Y'); + if (x[i][j] > 0 && x[i][j] == y[i][j]) res++; + } + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -1299,3 +1299,4 @@ for solving problems. | 3192 | Medium | [Minimum Operations to Make Binary Array Elements Equal to One II](Problems/3192.cpp) | | 3195 | Medium | [Find the Minimum Area to Cover All Ones I](Problems/3195.cpp) | | 3211 | Medium | [Generate Binary Strings Without Adjacent Zeros](Problems/3211.cpp) | +| 3212 | Medium | [Count Submatrices With Equal Frequency of X and Y](Problems/3212.cpp) |