problems: add pascals triangle ii
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
123c4ef5d7
commit
891c50440e
1 changed files with 16 additions and 0 deletions
16
problems/pascals-triangle-ii.cpp
Normal file
16
problems/pascals-triangle-ii.cpp
Normal 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;
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue