-
Notifications
You must be signed in to change notification settings - Fork 17
/
pascals-triangle-ii.py
78 lines (63 loc) · 1.64 KB
/
pascals-triangle-ii.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import unittest
from typing import List
class Solution:
def getRow(self, rowIndex: int) -> List[int]:
row = [1] + [0] * rowIndex
for level in range(1, rowIndex + 1):
for pos in reversed(range(1, level + 1)):
row[pos] = row[pos - 1] + row[pos]
return row
class TestSolution(unittest.TestCase):
def setUp(self):
self.sol = Solution()
def test_one(self):
assert self.sol.getRow(0) == [1]
def test_two(self):
assert self.sol.getRow(1) == [1, 1]
def test_three(self):
assert self.sol.getRow(2) == [1, 2, 1]
def test_four(self):
assert self.sol.getRow(3) == [1, 3, 3, 1]
def test_five(self):
assert self.sol.getRow(4) == [1, 4, 6, 4, 1]
def test_six(self):
assert self.sol.getRow(5) == [1, 5, 10, 10, 5, 1]
def test_six(self):
assert self.sol.getRow(33) == [
1,
33,
528,
5456,
40920,
237336,
1107568,
4272048,
13884156,
38567100,
92561040,
193536720,
354817320,
573166440,
818809200,
1037158320,
1166803110,
1166803110,
1037158320,
818809200,
573166440,
354817320,
193536720,
92561040,
38567100,
13884156,
4272048,
1107568,
237336,
40920,
5456,
528,
33,
1,
]
if __name__ == "__main__":
unittest.main()