Level
LeetCode Easy
Recruitment
// recursion : timeout
var tribonacci = function (n) {
  if (n === 0) return 0;
  if (n === 1) return 1;
  if (n === 2) return 1;

  return tribonacci(n - 1) + tribonacci(n - 2) + tribonacci(n - 3);
};

// for문
var tribonacci = function (n) {
  const tri = [0, 1, 1];
  for (let i = 3; i < n + 1; i++) {
    tri[i] = tri[i - 1] + tri[i - 2] + tri[i - 3];
  }
  return tri[n];
};