From 5dc18094bcbe3d7f3beb458df19c6147d23c785e Mon Sep 17 00:00:00 2001 From: jdy8739 Date: Sat, 7 Dec 2024 16:28:02 +0900 Subject: [PATCH 1/4] climbing-stairs solution --- climbing-stairs/jdy8739.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 climbing-stairs/jdy8739.js diff --git a/climbing-stairs/jdy8739.js b/climbing-stairs/jdy8739.js new file mode 100644 index 000000000..bb2554f01 --- /dev/null +++ b/climbing-stairs/jdy8739.js @@ -0,0 +1,20 @@ +/** + * @param {number} n + * @return {number} + */ +var climbStairs = function(n) { + let first = 1; + let second = 2; + + if (n <= 2) { + return n; + } + + for (let i=2; i Date: Sat, 7 Dec 2024 16:56:15 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=EA=B0=9C=ED=96=89=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- climbing-stairs/jdy8739.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/climbing-stairs/jdy8739.js b/climbing-stairs/jdy8739.js index bb2554f01..4778639ab 100644 --- a/climbing-stairs/jdy8739.js +++ b/climbing-stairs/jdy8739.js @@ -17,4 +17,6 @@ var climbStairs = function(n) { } return second; -}; \ No newline at end of file +}; + + From efa4da11b48d0c6437bc132c203c0441ab017235 Mon Sep 17 00:00:00 2001 From: jdy8739 Date: Sat, 14 Dec 2024 23:56:25 +0900 Subject: [PATCH 3/4] climbing-stairs solution --- coin-change/jdy8739.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 coin-change/jdy8739.js diff --git a/coin-change/jdy8739.js b/coin-change/jdy8739.js new file mode 100644 index 000000000..5e207e7cb --- /dev/null +++ b/coin-change/jdy8739.js @@ -0,0 +1,16 @@ +/** + * @param {number[]} coins + * @param {number} amount + * @return {number} + */ +var coinChange = function(coins, amount) { + const dp = [0, ...(new Array(amount).fill(amount + 1))]; + + for (coin of coins) { + for (let a = coin; a <= amount; a++) { + dp[a] = Math.min(dp[a], dp[a - coin] + 1); + } + } + + return dp[amount] < amount + 1 ? dp[amount] : -1 +}; \ No newline at end of file From dc2264d62dad368093926215abce507221214cf1 Mon Sep 17 00:00:00 2001 From: jdy8739 Date: Sun, 15 Dec 2024 00:15:10 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=ED=8C=8C=EC=9D=BC=20=EB=A7=88?= =?UTF-8?q?=EC=A7=80=EB=A7=89=20=EA=B0=9C=ED=96=89=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coin-change/jdy8739.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coin-change/jdy8739.js b/coin-change/jdy8739.js index 5e207e7cb..a508a2ab0 100644 --- a/coin-change/jdy8739.js +++ b/coin-change/jdy8739.js @@ -13,4 +13,5 @@ var coinChange = function(coins, amount) { } return dp[amount] < amount + 1 ? dp[amount] : -1 -}; \ No newline at end of file +}; +