求Pascal三角的某一层,要求O(n)复杂度。
vector getRow(int rowIndex) { vector ret(++rowIndex); for (int i = 0; i < rowIndex; ++i) { int last; for (int j = 0; j <= i; ++j) { if (j == 0 || j == i) { ret[j] = 1; last = 1; } else { int temp = ret[j]; ret[j] = last + ret[j]; last = temp; } } } return ret;}