# 119. Pascal’s Triangle I & II

`class Solution:    def generate(self, numRows: int) -> List[List[int]]:        pascal=[[]]*numRows        for i in range(numRows):            pascal[i]=*(i+1)            pascal[i],pascal[i][i]=1,1            for j in range(1,i):                pascal[i][j]=pascal[i-1][j-1]+pascal[i-1][j]        return(pascal)`
`class Solution:         def getRow(self, rowIndex: int) -> List[int]:           pascal=[[]]*(rowIndex+1)        for i in range(rowIndex+1):            pascal[i]=*(i+1)            pascal[i],pascal[i][i]=1,1            for j in range(1,i):                pascal[i][j]=pascal[i-1][j-1]+pascal[i-1][j]        return(pascal[-1])`
`class Solution:    def combinatorial(self,n,r):        res=1        for i in range(0,r):     #4c2= 4*3/1*2            res*=(n-i)            res//=(i+1)        return res        def getRow(self, rowIndex: int) -> List[int]:        result=[]        for i in range(rowIndex+1):            result.append(self.combinatorial(rowIndex,i))        return result            #Time O(rowIndex^2)    #Space O(rowIndex)`
`class Solution:         def getRow(self, rowIndex: int) -> List[int]:        res=        for i in range(1,rowIndex+1):            res.append(1)            for j in range(len(res)-2,0,-1):                res[j]=res[j-1]+res[j]        return(res)`

--

-- ## Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.