Simple python solution


  • 0
    D
    class Solution(object):
        def generate(self, numRows):
            result = []
            for i in range(numRows):
                row = [1]
                for j in range(i):
                    try:
                        row.append(result[-1][j] + result[-1][j+1])
                    except IndexError:
                        row.append(1)
                result.append(row)
            return result
    

Log in to reply
 

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