-
Notifications
You must be signed in to change notification settings - Fork 0
/
119.py
42 lines (32 loc) · 887 Bytes
/
119.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = ['"wuyadong" <[email protected]>']
class Solution(object):
def c(self, i, j):
total = 1
divide = 1
for k in xrange(0, j):
total *= i-k
for k in xrange(j, 0, -1):
divide *= k
return total / divide
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
n = rowIndex
array = []
if n == 0:
return [1]
if n == 1:
return [1, 1]
for i in xrange(0, n/2+1):
array.append(self.c(n, i))
if n % 2 == 0:
array += array[-2::-1]
else:
array += array[::-1]
return array
if __name__ == '__main__':
print Solution().getRow(4)