本文共 442 字,大约阅读时间需要 1 分钟。
class Solution {public: vector getRow(int rowIndex) { // Start typing your C/C++ solution below // DO NOT write int main() function vector ans(rowIndex+2, 0); vector tmp(rowIndex+2, 0); ans[1] = 1;//first row for(int i = 1; i <= rowIndex; ++i) { tmp = ans; for(int j = 1; j <= i+1; ++j) ans[j] = tmp[j-1]+tmp[j]; } ans.erase(ans.begin());//delete prefix zero return ans; }};
转载地址:http://nmxti.baihongyu.com/