Pascal's Triangle II

class Solution {
public:
    vector<int> getRow(int rowIndex) {
          vector<int> v;
          if( rowIndex < 0) return v;
          
          v.push_back(1);
          if(rowIndex == 0) return v;
          
          v.push_back(1);
          if(rowIndex == 1) return v;
          
           vector<int> v1;
          
          for(int row=2;row<=rowIndex;row++){
              
                v1.push_back(1); 
             int pre_len = v.size();
             for(int i=0;i<pre_len-1;i++){
                v1.push_back(v[i]+v[i+1]);
             }
                v1.push_back(1); 
                v=v1;      //vector 拷贝好方便啊
                v1.clear();
          }
          return v;
    }
};

 

你可能感兴趣的:(pascal)