Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- simulation
- Method
- Tree
- 자바
- two pointers
- implement
- SQL
- 코테
- Counting
- Class
- Number Theory
- 코딩테스트
- database
- Stack
- geometry
- dynamic programming
- Math
- hash table
- bit manipulation
- 구현
- array
- Binary Tree
- greedy
- java
- Data Structure
- sorting
- string
- Matrix
- 파이썬
- Binary Search
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1137. N-th Tribonacci Number 본문
1. Input
1) 정수 n
2. Output
1) n번째 트리보나치 수
2) T_0 = 0, T_1 = 1, T_2 = 1, T_n+3 = T_n + T_n+1 + T_n+2 (n>=0)
3. Constraint
1) 0 <= n <= 37
2) 0<= answer <= 2^31 - 1
4. Example
Input: n = 4 -> Output: 4
설명:
T_3 = 0 + 1 + 1 = 2
T_4 = 1 + 1 + 2 = 4
5. Code
1) 첫 코드(2022/07/06)
if(n==0)
return 0;
if(n==1 || n==2)
return 1;
int a=0, b=1, c=1, d=0;
for(int i=3 ; i<=n ; i++){
d = a+b+c;
a = b;
b = c;
c = d;
}
return d;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1221. Split a String in Balanced Strings (0) | 2022.12.23 |
---|---|
[LeetCode/Easy] 1154. Day of the Year (0) | 2022.12.20 |
[LeetCode/Easy] 1108. Defanging an IP Address (0) | 2022.12.20 |
[LeetCode/Easy] 1103. Distribute Candies to People (0) | 2022.12.20 |
[LeetCode/Easy] 1089. Duplicate Zeros (0) | 2022.12.20 |