118. Pascal's Triangle 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314151617181920class Solution {public: vector<vector<int>> generate(int numRows) { vector<vector<int>> ret = {{1}}; if(numRows==1) return ret; vector<int> row = {1}; for(int i=2;i<=numRows;++i){ int pre = row[0]; for(int j = 1;j<i-1 ; ++j){ int cur = row[j]; row[j] +=pre; pre = cur; } row.push_back(1); ret.push_back(row); } return ret; }}; analysis time complexity O(n) space complexity O(nm)