Pascal's Triangle II
Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.
vector<int> getRow(int rowIndex) {
vector<int> v(rowIndex+1,1);
for(int i=1;i<rowIndex;++i)
{
for(int j=i;j>0;--j)
{
v[j]=v[j]+v[j-1];
}
}
return v;
}
Comments
Post a Comment