class Solution {
public:
vector<vector<int> > generate(int numRows) {
vector<vector<int>> r(numRows);
for (int i = 0; i < numRows; i++) {
r[i].resize(i + 1);
r[i][0] = r[i][i] = 1;
for (int j = 1; j < i; j++)
r[i][j] = r[i  1][j  1] + r[i  1][j];
}
return r;
}
};
Maybe shortest c++ solution

Thanks for sharing.
My approach is a bit different, which is also short.
https://leetcode.com/discuss/94262/shortcsolutionusingonlyokextraspace


Nice ! Thanks!
Python version:class Solution(object): def generate(self, numRows): """ :type numRows: int :rtype: List[List[int]] """ all_rows = [None] * numRows for i in range(numRows): all_rows[i] = [None] * (i+1) all_rows[i][0] = all_rows[i][i] = 1 for j in range(1, i): all_rows[i][j] = all_rows[i1][j1] + all_rows[i1][j] return all_rows

@abhishek.bailore94 how many elements in
row i
@abhishek.bailore94 said in Maybe shortest c++ solution:
r[i].resize(i + 1); //What does this step do here?