My 40 ms Python iterative solution


  • 0
    S
    class Solution(object):
        def generate(self, numRows):
            n= numRows
            if n==0: return []
            if n==1: return [[1]]
            l = [[] for i in xrange(n)]
            l[0].append(1)
            for i in xrange(1,n):
                l[i].append(1)
                for j in xrange(1, len(l[i-1])):
                    l[i].append(l[i-1][j-1]+l[i-1][j])
                l[i].append(1)
            return l

Log in to reply
 

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