Simple Python 5 lines, 36ms


  • 4
    G
    def getRow(rowIndex):
        pascal = [1]*(rowIndex + 1)
        for i in range(2,rowIndex+1):
            for j in range(i-1,0,-1):
                pascal[j] += pascal[j-1]
        return pascal

  • 1
    I

    avoid range(... , ... , -1) will make the program run faster

    def getRow(rowIndex):
        rt=[1]*(rowIndex+1)
        for i in range(2, rowIndex+1):
            for j in range(1, i):
                rt[i-j]+=rt[i-j-1]
        return rt

Log in to reply
 

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