Simple Time O(n) and Space O(n) solution.

  • 0

    Observing that the element in the array is just iterative combination C_m_n, with m is the rowIndex and n is from 0 to rowIndex. What's more we can get the relationship between previous element and the current element to be calulated as defined in cmn function.

    class Solution(object):
        def cmn(self, m, n, last):
            return last*(m+1-n)/n
        def getRow(self, rowIndex):
            for i in range(rowIndex):
                ret.append(self.cmn(rowIndex, i+1, ret[i]))
            return ret

Log in to reply

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