Description
Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.
In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:
My solution
class Solution:
def getRow(self, rowIndex: int) -> List[int]:
array = [1] * 34
array[0] = [1]
array[1] = [1,1]
for i in range(2,34):
array[i] = [1]
for k in range(i-1):
array[i].append(array[i - 1][k] + array[i - 1][k + 1])
array[i].append(1)
return array[rowIndex]
문제 출처 : https://leetcode.com/problems/pascals-triangle-ii/
'Algorithm > Daily Coding Tests Challenge' 카테고리의 다른 글
[Leetcode] Medium : Number of Provinces (0) | 2021.11.08 |
---|---|
[Leetcode] Medium : Network Delay time (0) | 2021.10.13 |
[Leetcode] Easy : Pascal's Triangle (0) | 2021.10.10 |
[Leetcode] Easy: Climbing Stairs (0) | 2021.10.10 |
[Leetcode] Median : Find First and Last Position of Element in Sorted Array (0) | 2021.10.09 |