From db721a1db1727bb018b9a5102b851776a869418a Mon Sep 17 00:00:00 2001 From: Eatswap Date: Mon, 16 Oct 2023 23:30:34 +0800 Subject: [PATCH] add: 231016 --- cpp/2308/LC231016.cpp | 17 +++++++++++++++++ cpp/2308/defs.h | 5 +++++ 2 files changed, 22 insertions(+) create mode 100644 cpp/2308/LC231016.cpp diff --git a/cpp/2308/LC231016.cpp b/cpp/2308/LC231016.cpp new file mode 100644 index 0000000..52bb32a --- /dev/null +++ b/cpp/2308/LC231016.cpp @@ -0,0 +1,17 @@ +#include "defs.h" + +class LC231016 { +public: + static std::vector getRow(int rowIndex) noexcept; +}; + +std::vector LC231016::getRow(int rowIndex) noexcept { + int row[36] {1}; + int tmp[36] {1}; + for (int i = 0; i < rowIndex; ++i) { + for (int j = 1; j < 35; ++j) + tmp[j] = row[j] + row[j - 1]; + std::memcpy(row + 1, tmp + 1, 35 * sizeof(int)); + } + return {row, row + rowIndex + 1}; +} diff --git a/cpp/2308/defs.h b/cpp/2308/defs.h index c62930f..dc1274e 100644 --- a/cpp/2308/defs.h +++ b/cpp/2308/defs.h @@ -41,4 +41,9 @@ public: static int numWays(int, int); }; +class LC231016 { +public: + static std::vector getRow(int rowIndex) noexcept; +}; + #endif //LEETCODE_CPP_DEFS_H