leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0118.cpp (431B)


      1 class Solution {
      2   public:
      3     vector<vector<int>> generate(int numRows) {
      4         vector<vector<int>> res;
      5 
      6         for (int i = 0; i < numRows; i++) {
      7             vector<int> row;
      8             row.push_back(1);
      9             for (int j = 1; j < i; j++)
     10                 row.push_back(res[i - 1][j - 1] + res[i - 1][j]);
     11             if (i != 0) row.push_back(1);
     12             res.push_back(row);
     13         }
     14         return res;
     15     }
     16 };