标签:style blog color for io leetcode
class Solution { public: vector<int> getRow(int rowIndex) { int half = (rowIndex + 1) / 2; int len = half * 2 + !(rowIndex & 0x1); int* ra = new int[half + 1]; int* rb = new int[half + 1]; ra[0] = 1; rb[0] = 1; for (int i=1; i<=rowIndex; i++) { int h = (i + 1) / 2; int j = 1; for (; j<h; j++) { rb[j] = ra[j-1] + ra[j]; } if (!(i & 0x1)) { rb[j] = ra[j-1] * 2; } int* t = ra; ra = rb; rb = t; } vector<int> res(len, 0); for (int i=0; i<half; i++) { res[i] = ra[i]; res[len - i - 1] = ra[i]; } if (!(rowIndex & 0x1)) res[half] = ra[half]; return res; } };
不顺
LeetCode Pascal's Triangle II,布布扣,bubuko.com
标签:style blog color for io leetcode
原文地址:http://www.cnblogs.com/lailailai/p/3816065.html