From 489c17b329f885be2b9618f6e8c5e9ab2f02ee17 Mon Sep 17 00:00:00 2001 From: BangDori Date: Mon, 9 Jun 2025 12:19:19 +0900 Subject: [PATCH] =?UTF-8?q?[=EA=B0=95=EB=B3=91=EC=A4=80]=20Combination=20S?= =?UTF-8?q?um=20IV?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bangdori/377.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 bangdori/377.js diff --git a/bangdori/377.js b/bangdori/377.js new file mode 100644 index 0000000..720aa18 --- /dev/null +++ b/bangdori/377.js @@ -0,0 +1,25 @@ +/** + * @param {number[]} nums + * @param {number} target + * @return {number} + */ +var combinationSum4 = function (nums, target) { + const dp = Array(target + 1).fill(-1); + + const comb = (current) => { + if (current === 0) return 1; + if (current < 0) return 0; + if (dp[current] !== -1) return dp[current]; + + let count = 0; + for (const num of nums) { + count += comb(current - num); + } + dp[current] = count; + + return count; + }; + + comb(target); + return dp[target]; +};