diff options
author | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
---|---|---|
committer | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
commit | d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa (patch) | |
tree | 96df922dae2a5073d9a50ea70c7aae6aa37e3ebe /nth_tribonacci_number.py | |
download | leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.tar.gz leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.zip |
initial
Diffstat (limited to 'nth_tribonacci_number.py')
-rw-r--r-- | nth_tribonacci_number.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/nth_tribonacci_number.py b/nth_tribonacci_number.py new file mode 100644 index 0000000..c647286 --- /dev/null +++ b/nth_tribonacci_number.py @@ -0,0 +1,29 @@ +# 1137. N-th Tribonacci Number + +""" +the tribonacci sequence t^n is defined as follows +t0 = 0, t1 = 1, t2 = 1, & tn+3 = tn + tn+1 + tn+2 for n >= 0 +given n, return value of tn +eg. +n = 4, output: 4 +t3 = 0 + 1 + 1 = 2 +t4 = 1 + 1 + 2 = 4 +""" + + +class Solution(object): + def tribonacci(self, n): + """ + :type n: int + :rtype: int + """ + a, b, c = 1, 0, 0 + for _ in range(n): + a, b, c = b, c, a + b + c + return c + + +if __name__ == "__main__": + obj = Solution() + print(obj.tribonacci(4)) + print(obj.tribonacci(25)) |