标签:
This is simple. Just everything use current[j] += current[j-1]. But leave the first one to be "1". Then add another "1" to end.
1 class Solution { 2 public: 3 vector<vector<int> > generate(int numRows) { 4 vector<vector<int> > result; 5 if (numRows == 0) return result; 6 vector<int> current(1, 1); 7 result.push_back(current); 8 for (int i = 2; i <= numRows; i++) { 9 for (int j = current.size()-1; j > 0; j--) { 10 current[j] += current[j-1]; 11 } 12 current.push_back(1); 13 result.push_back(current); 14 } 15 return result; 16 } 17 };
LeetCode - Refresh - Pascal's Triangle
标签:
原文地址:http://www.cnblogs.com/shuashuashua/p/4355879.html