From 07e09296b16bb393737e8abe152aa8ec1f026da7 Mon Sep 17 00:00:00 2001 From: JEONGHWANMIN Date: Thu, 3 Oct 2024 19:58:50 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=EB=AC=B8=EC=A0=9C=ED=92=80?= =?UTF-8?q?=EC=9D=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- merge-two-sorted-lists/hwanmini.js | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 merge-two-sorted-lists/hwanmini.js diff --git a/merge-two-sorted-lists/hwanmini.js b/merge-two-sorted-lists/hwanmini.js new file mode 100644 index 000000000..46bfa28ae --- /dev/null +++ b/merge-two-sorted-lists/hwanmini.js @@ -0,0 +1,37 @@ +// 시간복잡도: O(m + n) +// 공간복잡도: O(m + n) + +/** + * Definition for singly-linked list. + * function ListNode(val, next) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + */ +/** + * @param {ListNode} list1 + * @param {ListNode} list2 + * @return {ListNode} + */ +var mergeTwoLists = function(list1, list2) { + let res = new ListNode() + let resCopy = res + + while (list1 && list2) { + if (list1.val < list2.val) { + res.next = new ListNode(list1.val); + list1 = list1.next; + } else { + res.next = new ListNode(list2.val); + list2 = list2.next; + } + + res = res.next + } + + if (list1) res.next = list1; + if (list2) res.next = list2 + + return resCopy.next +}; + From 6e537595e1a0dfe8446c64782e991c2f2e9d5e24 Mon Sep 17 00:00:00 2001 From: HwanMin <65848374+JEONGHWANMIN@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:38:51 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Feat:=20=EB=AC=B8=EC=A0=9C=ED=92=80?= =?UTF-8?q?=EC=9D=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clone-graph/hwanmini.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 clone-graph/hwanmini.js diff --git a/clone-graph/hwanmini.js b/clone-graph/hwanmini.js new file mode 100644 index 000000000..0d29e5bff --- /dev/null +++ b/clone-graph/hwanmini.js @@ -0,0 +1,39 @@ +// 노드 수 v, 간선 e +// 시간복잡도 O(v+e) +// 공간복잡도 O(v+e) + +/** + * // Definition for a _Node. + * function _Node(val, neighbors) { + * this.val = val === undefined ? 0 : val; + * this.neighbors = neighbors === undefined ? [] : neighbors; + * }; + */ + +/** + * @param {_Node} node + * @return {_Node} + */ +var cloneGraph = function(node) { + if (!node) return + + const visited = new Map() + visited.set(node, new _Node(node.val)) + + const que = [node] + + while (que.length) { + const curNode = que.shift() + + for (neighbor of curNode.neighbors) { + if (!visited.has(neighbor)) { + visited.set(neighbor, new _Node(neighbor.val)); + que.push(neighbor) + } + + visited.get(curNode).neighbors.push(visited.get(neighbor)) + } + } + + return visited.get(node) +}; \ No newline at end of file From 555f5581b93496eea918fee9a184a58a82497c2c Mon Sep 17 00:00:00 2001 From: HwanMin <65848374+JEONGHWANMIN@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:39:30 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Feat:=20=EB=AC=B8=EC=A0=9C=ED=92=80?= =?UTF-8?q?=EC=9D=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clone-graph/hwanmini.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clone-graph/hwanmini.js b/clone-graph/hwanmini.js index 0d29e5bff..80e364a5f 100644 --- a/clone-graph/hwanmini.js +++ b/clone-graph/hwanmini.js @@ -36,4 +36,4 @@ var cloneGraph = function(node) { } return visited.get(node) -}; \ No newline at end of file +}; From a4473c8d07fcd4a87869a1dbcb024d2b31b37223 Mon Sep 17 00:00:00 2001 From: HwanMin <65848374+JEONGHWANMIN@users.noreply.github.com> Date: Sun, 6 Oct 2024 02:46:24 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Refactor:=20=EA=B8=B0=EC=A1=B4=20=EB=85=B8?= =?UTF-8?q?=EB=93=9C=20=EC=9E=AC=ED=99=9C=EC=9A=A9=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- merge-two-sorted-lists/hwanmini.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/merge-two-sorted-lists/hwanmini.js b/merge-two-sorted-lists/hwanmini.js index 46bfa28ae..eced76a97 100644 --- a/merge-two-sorted-lists/hwanmini.js +++ b/merge-two-sorted-lists/hwanmini.js @@ -1,3 +1,4 @@ +// m: list1, n: list2 // 시간복잡도: O(m + n) // 공간복잡도: O(m + n) @@ -19,10 +20,10 @@ var mergeTwoLists = function(list1, list2) { while (list1 && list2) { if (list1.val < list2.val) { - res.next = new ListNode(list1.val); + res.next = list1 list1 = list1.next; } else { - res.next = new ListNode(list2.val); + res.next = list2 list2 = list2.next; }