Leetcode Problem
Pascal’s Triangle II
rowIndex가 주어졌을 때, 파스칼 삼각형에서 해당 층의 배열을 구하는 문제입니다.
1
2
3
4
5
6
class Solution:
def getRow(self, rowIndex: int) -> List[int]:
pascal = [[1]]
for i in range(1, rowIndex+1):
pascal.append([x + y for x, y in zip([0] + pascal[i-1], pascal[i-1] + [0])])
return pascal[rowIndex]
이전 solution의 풀이를 활용하여 해답을 구했습니다.
참고