Fast python (>95%)


  • 0
    O
            """n,k = n-1,k-1 + n-1,k"""
            if(numRows == 0):
                return []
    
            triangle = [[1]]
    
            for n in range(1, numRows):
                thisRow = []
                thisRow.append(1)
                for k in range(1, n):
                    #row 0 has 1 elem etc
                    #print (n,k)
                    thisRow.append(triangle[n-1][k-1] +
                               triangle[n-1][k])
    
                    #only need to calculate nums between 1..1
                thisRow.append(1)
                #first and last elem always 1
                triangle.append(thisRow)
                #print (triangle)
            return triangle```
    
    the key is to calculate the minimum possible number of things, and try and 
    avoid conditional statements I guess, and read around the problem as well

Log in to reply
 

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