-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPascal'sTriangleII.cpp
More file actions
39 lines (39 loc) · 1.12 KB
/
Pascal'sTriangleII.cpp
File metadata and controls
39 lines (39 loc) · 1.12 KB
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
39
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
God Bless Me BUG Free Forever
*/
/***
* 滚动数组
* 从上往下计算到第k行(从第0行开始)
* row[j] = row[j-1] + row[j]; 右边上一行的数据
* 用一个数组实现滚动
* 每一行从后往前计算,防止row[j]被覆盖
***/
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> row(rowIndex+1, 1);
for (int i = 1; i <= rowIndex; ++i)
for (int j = i-1; j >= 1; --j) // [0, i]
row[j] += row[j-1];
return row;
}
};