From 184be395b5776b7e64a000bedf808c298e077dea Mon Sep 17 00:00:00 2001 From: seungseung88 Date: Mon, 21 Apr 2025 22:55:01 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=ED=92=80=EC=9D=B41:=20Merge=20Two=20Sorted?= =?UTF-8?q?=20Lists=20#224?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- merge-two-sorted-lists/seungseung88.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 merge-two-sorted-lists/seungseung88.js diff --git a/merge-two-sorted-lists/seungseung88.js b/merge-two-sorted-lists/seungseung88.js new file mode 100644 index 000000000..9a0cc2616 --- /dev/null +++ b/merge-two-sorted-lists/seungseung88.js @@ -0,0 +1,23 @@ +/** + * 시간 복잡도: O(n + m) + * 공간 복잡도: O(1) + */ +var mergeTwoLists = function (list1, list2) { + const dummy = new ListNode(); + node = dummy; + + while (list1 && list2) { + if (list1.val < list2.val) { + node.next = list1; + list1 = list1.next; + } else { + node.next = list2; + list2 = list2.next; + } + node = node.next; + } + + node.next = list1 || list2; + + return dummy.next; +}; From af374c91468c7b09a64753eec0af20903dce5db3 Mon Sep 17 00:00:00 2001 From: seungseung88 Date: Mon, 21 Apr 2025 23:42:49 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=ED=92=80=EC=9D=B41:=20Combination=20Sum=20?= =?UTF-8?q?#254?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- combination-sum/seungseung88.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 combination-sum/seungseung88.js diff --git a/combination-sum/seungseung88.js b/combination-sum/seungseung88.js new file mode 100644 index 000000000..7bb7a6f26 --- /dev/null +++ b/combination-sum/seungseung88.js @@ -0,0 +1,27 @@ +/** + * 시간복잡도: O(2^n) + * 공간복잡도: O(target) + */ + +function combinationSum(canditates, target) { + const result = []; + const nums = []; + + function dfs(start, total) { + if (total > target) return; + if (total === target) result.push([...nums]); + + // 중복제거를 위해 start로 시작 + for (let i = start; i < canditates.length; i += 1) { + num = canditates[i]; + nums.push(num); + dfs(i, total + num); + nums.pop(); + } + } + + // 시작 인덱스, 누적 합 + dfs(0, 0); + + return result; +} From 3ef5a41afb2fcbda1174854ae49a0ae446eab80c Mon Sep 17 00:00:00 2001 From: seungseung88 Date: Tue, 22 Apr 2025 19:08:36 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=ED=92=80=EC=9D=B41:=20Decode=20Ways=20#268?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- decode-ways/seungseung88.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 decode-ways/seungseung88.js diff --git a/decode-ways/seungseung88.js b/decode-ways/seungseung88.js new file mode 100644 index 000000000..671bfec21 --- /dev/null +++ b/decode-ways/seungseung88.js @@ -0,0 +1,26 @@ +/** + * 시간 복잡도: O(n) + * 공간 복잡도: O(n) + */ +var numDecodings = function (s) { + const memo = new Map(); + memo.set(s.length, 1); + + function dfs(start) { + if (memo.has(start)) { + return memo.get(start); + } + + if (s[start] === '0') { + memo.set(start, 0); + } else if (start + 1 < s.length && parseInt(s.slice(start, start + 2)) < 27) { + memo.set(start, dfs(start + 1) + dfs(start + 2)); + } else { + memo.set(start, dfs(start + 1)); + } + + return memo.get(start); + } + + return dfs(0); +};