forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
35 lines (31 loc) · 765 Bytes
/
solution.cpp
File metadata and controls
35 lines (31 loc) · 765 Bytes
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
class Solution
{
public:
vector<vector<int> > generate(int numRows)
{
vector<vector<int> > result;
if(numRows == 0)
return result;
vector<int> temp;
temp.push_back(1);
result.push_back(temp);
if(numRows == 1)
return result;
temp.push_back(1);
result.push_back(temp);
if(numRows == 2)
return result;
for(int i=2;i<numRows;i++)
{
vector<int> temp;
temp.push_back(1);
for(int j=0;j<i-1;j++)
{
temp.push_back(result[i-1][j] + result[i-1][j+1]);
}
temp.push_back(1);
result.push_back(temp);
}
return result;
}
};