Pascal's Triangle II

时间:2014-10-05 23:21:59   收藏:0   阅读:328
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;
    }
};

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!