vector<int> getRow(int rowIndex) {
vector<int> array(rowIndex+1,0);
for (int i = 0; i <= rowIndex; i++) {
for (int j = i-1; j > 0; j--){
array[j] = array[j-1] + array[j];
}
array[i]=1;
}
return array;
}
//another
vector<int> getRow(int rowIndex) {
vector<int> array(rowIndex+1,1);
for (int i = 1; i <= rowIndex; i++) {
for (int j = i-1; j > 0; j--){
array[j] = array[j-1] + array[j];
}
}
return array;
}
No comments:
Post a Comment