From 5df89273710bddd67e9792249eebf8cd913023e5 Mon Sep 17 00:00:00 2001 From: Sagnik Mazumder Date: Sat, 10 Oct 2020 11:53:49 +0530 Subject: [PATCH] added solution to leetcode problem 1137 --- LeetCode/1137_N_th_Tribonacci_Number.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 LeetCode/1137_N_th_Tribonacci_Number.py diff --git a/LeetCode/1137_N_th_Tribonacci_Number.py b/LeetCode/1137_N_th_Tribonacci_Number.py new file mode 100644 index 0000000..8c01a86 --- /dev/null +++ b/LeetCode/1137_N_th_Tribonacci_Number.py @@ -0,0 +1,14 @@ +class Solution: + def tribonacci(self, n: int) -> int: + a, b, c = 0, 1, 1 + if n == 0: + return 0 + elif n == 1 or n == 2: + return 1 + else: + for _ in range(n - 2): + temp = a + b + c + a = b + b = c + c = temp + return temp