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; + } +};