From 703c3eb6fb8d294510504672afa1ad95a38add50 Mon Sep 17 00:00:00 2001 From: yoshimasataira Date: Wed, 15 Sep 2021 13:40:43 +0000 Subject: [PATCH] =?UTF-8?q?trib=E9=96=A2=E6=95=B0=E3=81=AE=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index bba68419..ad671cd9 100644 --- a/app.js +++ b/app.js @@ -1,12 +1,13 @@ 'use strict'; const memo = new Map(); memo.set(0, 0); -memo.set(1, 1); +memo.set(1, 0); +memo.set(2, 1); function trib(n) { if (memo.has(n)) { return memo.get(n); } - const value = trib(n - 1) + trib(n - 2); + const value = trib(n - 1) + trib(n - 2) + trib(n - 3); memo.set(n, value); return value; }