일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
29 | 30 |
Tags
- Writing
- 스탭퍼
- 읽기
- 개발자
- 링피트
- Problem Solving
- 30분
- English
- Daily Challenge
- realclass
- leetcode
- 만화도
- 10분
- 괜찮음
- 리얼 클래스
- FIT XR
- 뭐든
- 매일
- 잡생각
- 월간
- 운동
- 프로젝트
- 영어원서읽기
- 3줄정리
- 사이드
- 화상영어
- 미드시청
- 영어공부
- 쓰릴오브파이트
- 파비최
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.01.30 Today's Challenge 본문
https://leetcode.com/problems/n-th-tribonacci-number/
N-th Tribonacci Number - LeetCode
N-th Tribonacci Number - The Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0. Given n, return the value of Tn. Example 1: Input: n = 4 Output: 4 Explanation: T_3 = 0 + 1 + 1 = 2 T_4 = 1 + 1
leetcode.com
정말 간단한 피보나치 문제의 정말 소소한 변형
class Solution:
def tribonacci(self, n: int) -> int:
ar = [0, 1, 1, 2] + [0] * 40
if n <= 3:
return ar[n]
for i in range(4, 38):
ar[i] = ar[i-3] + ar[i-2] + ar[i-1]
return ar[n]
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.02.01 Today's Challenge (0) | 2023.02.01 |
---|---|
2023.01.31 Today's Challenge (0) | 2023.01.31 |
2023.01.29 Today's Challenge (0) | 2023.01.29 |
2023.01.28 Today's Challenge (0) | 2023.01.28 |
2023.01.27 Today's Challenge (0) | 2023.01.27 |
Comments