http://oj.leetcode.com/problems/pascals-triangle-ii/
这道题解法和上一题类似
但是申请过多数组浪费空间
还可以使用递归 但是效率太低 case9就已经超时
根据杨辉三角的特性
第n行为1,C(n,1),C(n,2)......C(n,n-1),C(n,n)
可以使用排列组合来做
import math
class Solution:
# @return a list of integers
def getRow(self, rowIndex):
array=[]
for i in range(rowIndex+1):#初始化为1
array.append(1)
for j in range(1,rowIndex):
array[j]=math.factorial(rowIndex)/(math.factorial(j)*math.factorial(rowIndex-j))
return array