From 57976e72fb0ae8789c8694878aa04440a865138a Mon Sep 17 00:00:00 2001 From: Eatswap Date: Thu, 2 Mar 2023 01:05:02 +0800 Subject: [PATCH] add: 230301-CN --- cpp/2303/230301-CN.cpp | 28 ++++++++++++++++++++++++++++ cpp/2303/CMakeLists.txt | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 cpp/2303/230301-CN.cpp diff --git a/cpp/2303/230301-CN.cpp b/cpp/2303/230301-CN.cpp new file mode 100644 index 0000000..74f39b8 --- /dev/null +++ b/cpp/2303/230301-CN.cpp @@ -0,0 +1,28 @@ +#include + +/** + * 2373. Largest Local Values in a Matrix + * + * You are given an n x n integer matrix grid. + * + * Generate an integer matrix maxLocal of size (n - 2) x (n - 2) such that: + * + * maxLocal[i][j] is equal to the largest value of the 3 x 3 matrix in grid centered around row i + 1 and column j + 1. + * In other words, we want to find the largest value in every contiguous 3 x 3 matrix in grid. + * + * Return the generated matrix. + */ + +class Solution { +public: + static std::vector> largestLocal(const std::vector>& grid) { + const int n = grid.size(), t = n - 2; + auto ret = std::vector>(t, std::vector(t)); + for (int i = 0; i < t; ++i) + for (int j = 0; j < t; ++j) + for (int k = 0; k < 3; ++k) + for (int l = 0; l < 3; ++l) + ret[i][j] = std::max(ret[i][j], grid[i + k][j + l]); + return ret; + } +}; diff --git a/cpp/2303/CMakeLists.txt b/cpp/2303/CMakeLists.txt index ecd3673..c66e60c 100644 --- a/cpp/2303/CMakeLists.txt +++ b/cpp/2303/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2303) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2303 230301.cpp) +ADD_EXECUTABLE(2303 230301-CN.cpp)