-
2. Pascal's TriangleProblem Solving 2022. 8. 23. 00:35728x90
https://leetcode.com/problems/pascals-triangle/
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
그림 덕분에 문제 이해하기가 쉬웠음
class Solution: def generate(self, numRows: int) -> List[List[int]]: pascal = [] for i in range(numRows): row = [] for j in range(i+1): elem = 1 if i >= 2 and j > 0 and j < i: elem = pascal[i - 1][j - 1] + pascal[i - 1][j] row.append(elem) pascal.append(row) return pascal
정작 문제 푸는 것보다 이중 리스트 구조 접근과 리스트에 integer append 하는 걸 해결하는 게 더 걸림ㅠ
'Problem Solving' 카테고리의 다른 글
6. 문자열 내 p와 y의 개수 (0) 2022.08.27 5. 스킬트리 (0) 2022.08.26 4. 나누어 떨어지는 숫자 배열 (0) 2022.08.25 3. Plus One (2) 2022.08.24 1. Assign Cookies (2) 2022.08.22