leetcode

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

commit f626d2f685e5f44a350184ef3ee9218c79d43a0f
parent d9d6ceec6ca6e72b28c3feecf9c5693e43514778
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Thu,  8 Jun 2023 12:41:04 +0200

Daily Problem

Diffstat:
AProblems/1351.cpp | 16++++++++++++++++
MREADME.md | 1+
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/Problems/1351.cpp b/Problems/1351.cpp @@ -0,0 +1,16 @@ +class Solution { +public: + int countNegatives(vector<vector<int>> &grid) { + int n = grid.size(), m = grid[0].size(), res = 0; + int i = n - 1, j = 0, cnt = 0; + while (i >= 0 && j < m) { + if (grid[i][j] < 0) { + res += m - j; + i--; + } else { + j++; + } + } + return res; + } +}; diff --git a/README.md b/README.md @@ -441,6 +441,7 @@ for solving problems. | 1342 | Easy | [Number of Steps to Reduce a Number to Zero](Problems/1342.cpp) | | 1345 | Hard | [Jump Game IV](Problems/1345.cpp) | | 1346 | Easy | [Check if N and Its Double Exist](Problems/1346.cpp) | +| 1351 | Easy | [Count Negative Numbers in a Sorted Matrix](Problems/1351.cpp) | | 1361 | Medium | [Validate Binary Tree Nodes](Problems/1361.cpp) | | 1367 | Medium | [Linked List in Binary Tree ](Problems/1367.cpp) | | 1372 | Medium | [Longest ZigZag Path in a Binary Tree](Problems/1372.cpp) |