码迷,mamicode.com
首页 > 其他好文 > 详细

Pascal's Triangle II

时间:2014-10-06 00:58:39      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:blog   io   for   2014   c   on   log   r   size   

class Solution {
public:
    vector<int> getRow(int rowIndex) {
       vector<int> result;
       int i = 0;
       int j = 0;
       if(rowIndex < 0) {
           return result;
       }
       
       result.push_back(1);
       if(rowIndex == 0){
           return result;
       }
       
       for(i = 1; i <= rowIndex; i++){
           for(j = result.size() - 1; j > 0; j--){//注意,此处不可以写成for(j =1; j j<result.size(); j++){

               result[j] = result[j] + result[j - 1];
           }
           result.push_back(1);
       }
       return result;
    }
};

Pascal's Triangle II

标签:blog   io   for   2014   c   on   log   r   size   

原文地址:http://blog.csdn.net/wyj7260/article/details/39807355

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!