Python code using formula


  • 0
    H
    class Solution:
        # @return a list of integers
        def getRow(self, rowIndex):
            row = list(1 for i in xrange(rowIndex + 1))
            import math
            for i in xrange(rowIndex + 1):
                row[i] = int(math.factorial(rowIndex)/math.factorial(i)/math.factorial(rowIndex - i))
            
            return row
    

    I do not think that I could remember this during interview so I will rewrite it with no extra space algorighm


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.