Advertisement
nikunjsoni

118

Jun 21st, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     vector<vector<int>> generate(int numRows) {
  4.         vector<vector<int>> ans;
  5.         ans.push_back(vector<int>(1,1));
  6.        
  7.         for(int i=1; i<numRows; i++){
  8.             vector<int> row;
  9.             row.push_back(1);
  10.             for(int j=1; j<i; j++){
  11.                 row.push_back(ans[i-1][j-1]+ans[i-1][j]);
  12.             }
  13.             row.push_back(1);
  14.             ans.push_back(row);
  15.         }
  16.         return ans;
  17.     }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement