118. Pascal's Triangle
· 약 1분
[Pascal's Triangle - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com](https://leetcode.com/problems/pascals-triangle/)
1. 구현
from typing import *
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
answer = [[1]]
if numRows == 1:
return answer
elif numRows == 2:
answer.append([1, 1])
return answer
else:
answer.append([1, 1])
for index in range(2, numRows):
cur, temp = 0, []
while cur < index + 1:
if cur in [0, index]:
temp.append(1)
else:
temp.append(answer[index - 1][cur - 1] + answer[index - 1][cur])
cur += 1
answer.append(temp)
return answer

[파스칼의 삼각형 - 위키백과, 우리 모두의 백과사전
위키백과, 우리 모두의 백과사전. 파스칼의 삼각형(Pascal's triangle)은 수학에서 이항계수를 삼각형 모양의 기하학적 형태로 배열한 것이다. 이것은 블레즈 파스칼에 의해 이름 붙여졌으나 이미 수
ko.wikipedia.org](https://ko.wikipedia.org/wiki/%ED%8C%8C%EC%8A%A4%EC%B9%BC%EC%9D%98_%EC%82%BC%EA%B0%81%ED%98%95)
파스칼의 삼각형을 구하는 문제다.
위 풀이가 DP라고 말할 수 있는가는 약간 의문이지만;