forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
38 lines (30 loc) · 799 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/// Source : https://leetcode.com/problems/pascals-triangle/description/
/// Author : liuyubobobo
/// Time : 2018-06-03
#include <iostream>
#include <vector>
using namespace std;
/// Simulation (Dynamic Programming)
/// Time Complexity: O(n^2)
/// Space Complexity: O(1)
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> res;
if(numRows <= 0)
return res;
res.push_back({1});
for(int i = 1 ; i < numRows ; i ++){
vector<int> row;
row.push_back(1);
for(int j = 1 ; j < i ; j ++)
row.push_back(res[i-1][j-1] + res[i-1][j]);
row.push_back(1);
res.push_back(row);
}
return res;
}
};
int main() {
return 0;
}