일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Writing
- 10분
- Daily Challenge
- 미드시청
- 개발자
- 파비최
- 운동
- 영어공부
- English
- 괜찮음
- 잡생각
- 쓰릴오브파이트
- 사이드
- 화상영어
- 30분
- 만화도
- 3줄정리
- 리얼 클래스
- 프로젝트
- realclass
- FIT XR
- Problem Solving
- leetcode
- 스탭퍼
- 영어원서읽기
- 뭐든
- 월간
- 링피트
- 읽기
- 매일
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.09.08 Today's Challenge 본문
https://leetcode.com/problems/pascals-triangle/
Pascal's Triangle - LeetCode
Can you solve this real interview question? Pascal's Triangle - Given an integer numRows, return the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: [https://upload.wikimedia.o
leetcode.com
오랫만에 스스로 풀어본 문제!
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
ar = [[], [1], [1, 1]]
for i in range(3, 31):
a = []
for j in range(i):
if j == 0 or j == i - 1:
a.append(1)
continue
a.append(ar[i - 1][j - 1] + ar[i - 1][j])
ar.append(a)
return ar[1:numRows+1]
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.09.10 Today's Challenge (0) | 2023.09.10 |
---|---|
2023.09.09 Today's Challenge (0) | 2023.09.09 |
2023.09.07 Today's Challenge (0) | 2023.09.07 |
2023.09.06 Today's Challenge (0) | 2023.09.06 |
2023.09.05 Today's Challenge (0) | 2023.09.05 |
Comments