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 |
Tags
- 데이콘
- 맥북
- leetcode
- PYTHON
- programmers
- 편스토랑 우승상품
- SW Expert Academy
- 파이썬
- ChatGPT
- github
- 백준
- 금융문자분석경진대회
- 프로그래머스 파이썬
- hackerrank
- AI 경진대회
- Baekjoon
- 우분투
- dacon
- gs25
- 더현대서울 맛집
- Git
- ubuntu
- Kaggle
- Real or Not? NLP with Disaster Tweets
- 코로나19
- 편스토랑
- 캐치카페
- 자연어처리
- Docker
- 프로그래머스
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


SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'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 |