标签:style blog color 代码 for leetcode
class Solution { public: vector<vector<int> > generate(int numRows) { vector<vector<int> > res; if (numRows < 1) return res; vector<int> row(1, 1); res.push_back(row); for (int i=2; i<=numRows; i++) { // vector<int> &last = res.back(); res.push_back(vector<int>(i, 1)); vector<int> &crow = res.back(); int half = i / 2; int j = 1; for (; j<half; j++) { crow[i-j-1] = crow[j] = res[i-2][j] + res[i-2][j-1]; } if (i & 0x1) { crow[j] = res[i-2][j] * 2; } } return res; } };
上一列用代码中注释掉的引用代指的话就一直runtime error
LeetCode Pascal's Triangle,布布扣,bubuko.com
标签:style blog color 代码 for leetcode
原文地址:http://www.cnblogs.com/lailailai/p/3816131.html