1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 17:56:55 +02:00

problems: add pascals triangle ii

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-07-19 16:48:05 +02:00
parent 123c4ef5d7
commit 891c50440e
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,16 @@
class Solution {
public:
vector<int> getRow(int rowIndex)
{
vector<int> result;
result.push_back(1);
for (auto k = 0; k < rowIndex; k++) {
auto next = static_cast<int>(
static_cast<long>(result.back()) * (rowIndex - k) / (k + 1));
result.push_back(next);
}
return result;
}
};