Find the Nth row in Pascal 's Triangle | Function to find the elements of rowIndex in Pascal 's Triangle ; 1 st element of every row is 1 ; Check if the row that has to be returned is the first row ; Generate the previous row ; Generate the elements of the current row by the help of the previous row ; Return the row ; Driver Program
def getRow ( rowIndex ) : NEW_LINE INDENT currow = [ ] NEW_LINE currow . append ( 1 ) NEW_LINE if ( rowIndex == 0 ) : NEW_LINE INDENT return currow NEW_LINE DEDENT prev = getRow ( rowIndex - 1 ) NEW_LINE for i in range ( 1 , len ( prev ) ) : NEW_LINE INDENT curr = prev [ i - 1 ] + prev [ i ] NEW_LINE currow . append ( curr ) NEW_LINE DEDENT currow . append ( 1 ) NEW_LINE return currow NEW_LINE DEDENT n = 3 NEW_LINE arr = getRow ( n ) NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT if ( i == ( len ( arr ) - 1 ) ) : NEW_LINE INDENT print ( arr [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( arr [ i ] , end = " , ▁ " ) NEW_LINE DEDENT DEDENT