Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- hackerrank
- Baekjoon
- SW Expert Academy
- 편스토랑
- 백준
- Real or Not? NLP with Disaster Tweets
- ChatGPT
- 더현대서울 맛집
- 맥북
- ubuntu
- 프로그래머스
- Docker
- dacon
- programmers
- 우분투
- 데이콘
- Git
- Kaggle
- 캐치카페
- 편스토랑 우승상품
- PYTHON
- gs25
- leetcode
- 프로그래머스 파이썬
- 코로나19
- 파이썬
- 자연어처리
- 금융문자분석경진대회
- AI 경진대회
- github
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1137. N-th Tribonacci Number (Python) 본문
728x90
반응형
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 + 2 = 4
Example 2:
Input: n = 25
Output: 1389537
Constraints:
- 0 <= n <= 37
- The answer is guaranteed to fit within a 32-bit integer, ie. answer <= 2^31 - 1.
Solution
class Solution:
def tribonacci(self, n: int) -> int:
fiboNum = 0
if n == 1:
fiboNum = 1
elif n == 2:
fiboNum = 1
elif n == 3:
fiboNum = 2
elif n > 3:
fibo = [0] * (n)
fibo[0] = 1
fibo[1] = 1
fibo[2] = 2
for i in range(3, n):
fibo[i] = fibo[i-1] + fibo[i-2] + fibo[i-3]
fiboNum = fibo[n-1]
return fiboNum
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 1380. Lucky Numbers in a Matrix (Python) (0) | 2020.11.04 |
---|---|
[leetCode] 1351. Count Negative Numbers in a Sorted Matrix (Python) (0) | 2020.11.03 |
[leetCode] 509. Fibonacci Number (Python) (0) | 2020.11.01 |
[leetCode] 482. License Key Formatting (Python) (0) | 2020.10.31 |
[leetCode] 219. Contains Duplicate II (Python) (0) | 2020.10.28 |
Comments