[리트코드] 1137. N-th Tribonacci Number




1137. N-th Tribonacci Number

리트코드

나의 풀이

/**
 * @param {number} n
 * @return {number}
 */
var tribonacci = function (n) {
  if (n === 0) return 0;
  const tribonacci = [0, 1, 1];
  for (let i = 3; i <= n; i++) {
    tribonacci[i] = tribonacci[i - 3] + tribonacci[i - 2] + tribonacci[i - 1];
  }
  return tribonacci[n];
};

Runtime: 68 ms, faster than 87.20% of JavaScript online submissions for N-th Tribonacci Number.