A relative concise Python code


  • 0
    P
    class Solution:
        # @return a list of lists of integers
        def generate(self, numRows):
            ans = []
            if numRows == 0:
                return ans
            for i in range(numRows):
                t = []
                w = 1
                for j in range(0, (i+1)/2):
                    t.append(w)
                    w = w*(i-j)/(j+1)
                if i%2 == 1:
                    ans.append(t+t[::-1])
                else:
                    ans.append(t+[w]+t[::-1])
            return ans

Log in to reply
 

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