Class Solution

java.lang.Object
g1101_1200.s1137_n_th_tribonacci_number.Solution

public class Solution extends Object
1137 - N-th Tribonacci Number.<p>Easy</p> <p>The Tribonacci sequence T<sub>n</sub> is defined as follows:</p> <p>T<sub>0</sub> = 0, T<sub>1</sub> = 1, T<sub>2</sub> = 1, and T<sub>n+3</sub> = T<sub>n</sub> + T<sub>n+1</sub> + T<sub>n+2</sub> for n >= 0.</p> <p>Given <code>n</code>, return the value of T<sub>n</sub>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 4</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> T_3 = 0 + 1 + 1 = 2 T_4 = 1 + 1 + 2 = 4</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 25</p> <p><strong>Output:</strong> 1389537</p> <p><strong>Constraints:</strong></p> <ul> <li><code>0 <= n <= 37</code></li> <li>The answer is guaranteed to fit within a 32-bit integer, ie. <code>answer <= 2^31 - 1</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • tribonacci

      public int tribonacci(int n)