O(k) + 2 solution


  • -1
    G
    class Solution(object):
    def getRow(self, rowIndex):
        """
        :type rowIndex: int
        :rtype: List[int]
        """
        rv, tmp1,tmp2 = [1]*(rowIndex+1), 1, 1
        for i in range(1,rowIndex+1):
            for j in range(1,i):
                tmp1= rv[j]
                rv[j] = rv[j] + tmp2
                tmp2 = tmp1
        return rv

  • 1
    R

    O(k) + 2

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

Log in to reply
 

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