Simple python answer 5-lines


  • 2
    H
    class Solution(object):
    def getRow(self, rowIndex):
        """
        :type rowIndex: int
        :rtype: List[int]
        """
        res = [1] + [0] * rowIndex
        for i in range(1, rowIndex+1):
            for j in range(i,0,-1):
                res[j] = res[j] + res[j-1]
        return res

  • 0
    Z

    Just found yours or I will post mine as a new post :)

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

Log in to reply
 

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