From 66b3cac2c7e62e4ee5c4aae316611b39fac740b2 Mon Sep 17 00:00:00 2001 From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com> Date: Mon, 27 Sep 2021 21:23:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E70.=E7=88=AC=E6=A5=BC?= =?UTF-8?q?=E6=A2=AF=E5=AE=8C=E5=85=A8=E8=83=8C=E5=8C=85=E7=89=88=E6=9C=AC?= =?UTF-8?q?=20JavaScript=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0070.爬楼梯完全背包版本.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/problems/0070.爬楼梯完全背包版本.md b/problems/0070.爬楼梯完全背包版本.md index 4410dbaf..097ecfdb 100644 --- a/problems/0070.爬楼梯完全背包版本.md +++ b/problems/0070.爬楼梯完全背包版本.md @@ -186,6 +186,20 @@ func climbStairs(n int) int { } ``` +JavaScript: +```javascript +var climbStairs = function(n) { + const dp = new Array(n+1).fill(0); + const weight = [1,2]; + dp[0] = 1; + for(let i = 0; i <= n; i++){ //先遍历背包 + for(let j = 0; j < weight.length; j++){ // 再遍历物品 + if(i >= weight[j]) dp[i] += dp[i-weight[j]]; + } + } + return dp[n]; +}; +``` -----------------------