1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
class Solution {
public:
vector<int> getRow(int rowIndex) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
rowIndex++;
vector<int> ans(rowIndex);
if(rowIndex == 1)
{
ans[0] = 1;
}
else
if(rowIndex == 2)
{
ans[0] = 1;
ans[1] = 1;
}
else
{
ans[0] = 1;
ans[1] = 2;
ans[2] = 1;
for(int i = 4;i <= rowIndex;i++)
{
ans[0] = 1;
ans[i-1] = 1;
for(int j = i-2;j >= 1;j--)
{
ans[j] = ans[j-1] + ans[j];
}
}
}
return ans;
}
};
|