From 891c50440e9e46e3f06ab893ba5942341d3d82ea Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Tue, 19 Jul 2022 16:48:05 +0200 Subject: [PATCH] problems: add pascals triangle ii Signed-off-by: Matej Focko --- problems/pascals-triangle-ii.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 problems/pascals-triangle-ii.cpp diff --git a/problems/pascals-triangle-ii.cpp b/problems/pascals-triangle-ii.cpp new file mode 100644 index 0000000..f4f5db4 --- /dev/null +++ b/problems/pascals-triangle-ii.cpp @@ -0,0 +1,16 @@ +class Solution { +public: + vector getRow(int rowIndex) + { + vector result; + + result.push_back(1); + for (auto k = 0; k < rowIndex; k++) { + auto next = static_cast( + static_cast(result.back()) * (rowIndex - k) / (k + 1)); + result.push_back(next); + } + + return result; + } +};