leetcode

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

commit 318897c92a0e546b901a416a8a9d95fa5dabb802
parent f33f4fe8a7e639cc3ca7fe05fc09a206f3f26ee6
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri, 19 Jul 2024 22:36:52 +0200

Daily Problem

Diffstat:
AProblems/1380.cpp | 29+++++++++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/Problems/1380.cpp b/Problems/1380.cpp @@ -0,0 +1,29 @@ +class Solution { + public: + vector<int> luckyNumbers(const vector<vector<int>> &matrix) const { + static int row[51], col[51]; + const int n = size(matrix); + const int m = size(matrix[0]); + vector<int> res; + + memset(row, 0x7F, sizeof(row)); + memset(col, 0x00, sizeof(col)); + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + row[i] = min(row[i], matrix[i][j]); + col[j] = max(col[j], matrix[i][j]); + } + } + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (row[i] != matrix[i][j]) continue; + if (col[j] != matrix[i][j]) continue; + res.push_back(matrix[i][j]); + } + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -793,6 +793,7 @@ for solving problems. | 1376 | Medium | [Time Needed to Inform All Employees](Problems/1376.cpp) | | 1378 | Easy | [Replace Employee ID With The Unique Identifier](Problems/1378.cpp) | | 1379 | Easy | [Find a Corresponding Node of a Binary Tree in a Clone of That Tree](Problems/1379.cpp) | +| 1380 | Easy | [Lucky Numbers in a Matrix](Problems/1380.cpp) | | 1381 | Medium | [Design a Stack With Increment Operation](Problems/1381.cpp) | | 1382 | Medium | [Balance a Binary Search Tree](Problems/1382.cpp) | | 1387 | Medium | [Sort Integers by The Power Value](Problems/1387.cpp) |