代码改变世界

leetcode - Pascal's Triangle II

2013-10-27 14:48  张汉生  阅读(178)  评论(0编辑  收藏  举报

 

 1 class Solution {
 2 public:
 3     vector<int> getRow(int rowIndex) {
 4         // Note: The Solution object is instantiated only once and is reused by each test case.
 5         vector<int> rlt(rowIndex+1, 1);
 6         for (int i=0; i<=rowIndex; i++){
 7             int last = 1;
 8             int cur = 1;
 9             for (int j=1; j<i; j++){
10                 cur = rlt[j];
11                 rlt[j] = cur + last;
12                 last = cur;
13             }
14         }
15         return rlt;
16     }
17 };