moonlightshadow123
6/21/2017 - 8:34 AM

119. Pascal's Triangle II

  1. Pascal's Triangle II
class Solution(object):
    def getRow(self, rowIndex):
        """
        :type rowIndex: int
        :rtype: List[int]
        """
        row = [0]*(rowIndex+1)
        row[0] = 1
        for i in range(1, rowIndex+1):
            for j in range(i, 0, -1):
                row[j] = row[j] + row[j-1]
        return row

https://leetcode.com/problems/pascals-triangle-ii/#/description

Given an index k, return the kth row of the Pascal's triangle.

For example, given k = 3, Return [1,3,3,1].