Search

Pascal's Triangle

문제 설명 : 파스칼의 삼각형을 구현
풀이 방법 : 미리 삼각형을 나타낸 다중 리스트를 정의한 후, 규칙에 맞게 값을 설정
성공 코드
class Solution: def generate(self, numRows: int) -> List[List[int]]: result = [] for i in range(numRows): temp = [1] * (i + 1) # 규칙에 맞게 나머지를 채워준다 for j in range(1, i // 2 + 1): temp[j] = result[-1][j - 1] + result[-1][j] temp[~j] = result[-1][j - 1] + result[-1][j] result.append(temp) return result
Python
복사