From 44e0e7edc91947ca21edd7742b8a20b200f7a34d Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Wed, 23 Sep 2026 23:37:36 +0900 Subject: [PATCH] 1137. N-th Tribonacci Number --- .../1137. N-th Tribonacci Number.java" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/1137. N-th Tribonacci Number.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/1137. N-th Tribonacci Number.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/1137. N-th Tribonacci Number.java" new file mode 100644 index 00000000..fcbd10b6 --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/1137. N-th Tribonacci Number.java" @@ -0,0 +1,18 @@ +class Solution { + public int tribonacci(int n) { + if(n == 0) return 0; + if(n < 3) return 1; + + int[] tri = new int[n+1]; + + tri[0] = 0; + tri[1] = 1; + tri[2] = 1; + + for(int i=3; i<=n; i++) { + tri[i] = tri[i-1] + tri[i-2] + tri[i-3]; + } + + return tri[n]; + } +} \ No newline at end of file