From 498a1d2bdf770246bfa7cb224bd1d14baf58b363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Wed, 13 Aug 2025 14:29:22 +0900 Subject: [PATCH 1/6] merge-two-sorted-lists --- merge-two-sorted-lists/jun0811.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 merge-two-sorted-lists/jun0811.js diff --git a/merge-two-sorted-lists/jun0811.js b/merge-two-sorted-lists/jun0811.js new file mode 100644 index 000000000..1a3ef292e --- /dev/null +++ b/merge-two-sorted-lists/jun0811.js @@ -0,0 +1,20 @@ +/** + * Definition for singly-linked list. + * function ListNode(val, next) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + */ + +var mergeTwoLists = function (list1, list2) { + if (!list1) return list2; + else if (!list2) return list1; + + if (list1.val <= list2.val) { + list1.next = mergeTwoLists(list1.next, list2); + return list1; + } else { + list2.next = mergeTwoLists(list1, list2.next); + return list2; + } +}; From 4451bf862f63e310405d68409f6b5d27d4f5e18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Wed, 13 Aug 2025 14:30:59 +0900 Subject: [PATCH 2/6] Maximum Depth of Binary Tree --- maximum-depth-of-binary-tree/jun0811.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 maximum-depth-of-binary-tree/jun0811.js diff --git a/maximum-depth-of-binary-tree/jun0811.js b/maximum-depth-of-binary-tree/jun0811.js new file mode 100644 index 000000000..e69de29bb From 1507910def4ac1adb1b89e012d805dcd55ab6929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Wed, 13 Aug 2025 14:32:51 +0900 Subject: [PATCH 3/6] find-minimum-in-rotated-sorted-array --- find-minimum-in-rotated-sorted-array/jun0811.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 find-minimum-in-rotated-sorted-array/jun0811.js diff --git a/find-minimum-in-rotated-sorted-array/jun0811.js b/find-minimum-in-rotated-sorted-array/jun0811.js new file mode 100644 index 000000000..145a30a77 --- /dev/null +++ b/find-minimum-in-rotated-sorted-array/jun0811.js @@ -0,0 +1,16 @@ +var findMin = function (nums) { + let left = 0, + right = nums.length - 1; + + while (left < right) { + const mid = Math.floor((left + right) / 2); + + if (nums[mid] > nums[right]) { + left = mid + 1; // 최솟값이 오른쪽에 있음 + } else { + right = mid; // 최솟값이 왼쪽에 있음 (mid 포함) + } + } + + return nums[left]; +}; From f77974a1c532dce8727ac511d816e416c76553fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Wed, 13 Aug 2025 14:33:13 +0900 Subject: [PATCH 4/6] maximum-depth-of-binary-tree --- maximum-depth-of-binary-tree/jun0811.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/maximum-depth-of-binary-tree/jun0811.js b/maximum-depth-of-binary-tree/jun0811.js index e69de29bb..15f00f438 100644 --- a/maximum-depth-of-binary-tree/jun0811.js +++ b/maximum-depth-of-binary-tree/jun0811.js @@ -0,0 +1,22 @@ +var maxDepth = function (root) { + let res = 0; + + if (!root) return res; // root 자체가 없을 경우만 0 + + function check(node, depth) { + if (!node.left && !node.right) { + res = Math.max(res, depth); + return; + } + + if (node.left) { + check(node.left, depth + 1); + } + if (node.right) { + check(node.right, depth + 1); + } + } + + check(root, 1); // 루트부터 시작 + return res; +}; From f1f79332a08bae597d35f4b277fe40fd82e7629b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Wed, 13 Aug 2025 14:33:42 +0900 Subject: [PATCH 5/6] word-search --- word-search/jun0811.js | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 word-search/jun0811.js diff --git a/word-search/jun0811.js b/word-search/jun0811.js new file mode 100644 index 000000000..ac31cba3d --- /dev/null +++ b/word-search/jun0811.js @@ -0,0 +1,58 @@ +/** + * @param {character[][]} board + * @param {string} word + * @return {boolean} + */ + +const directions = [ + [0, -1], + [1, 0], + [-1, 0], + [0, 1], +]; + +var exist = function (board, word) { + const cols = board[0].length; // 가로 (열 개수) + const rows = board.length; // 세로 (행 개수) + let res = false; + + for (let col = 0; col < cols; col++) { + for (let row = 0; row < rows; row++) { + if (board[row][col] != word[0]) continue; + + const visited = Array.from({ length: rows }, () => + Array(cols).fill(false) + ); + if (res) break; + dfs(row, col, board[row][col], visited); + } + } + + function check(row, col) { + if (!(row >= 0 && row < rows)) return false; + if (!(col >= 0 && col < cols)) return false; + return true; + } + + function dfs(row, col, str, visited) { + if (str == word) { + res = true; + return; + } + if (str.length >= word.length) return; + visited[row][col] = true; + + for (const direction of directions) { + const [d_r, d_c] = direction; + const newCol = col + d_c; + const newRow = row + d_r; + + if (check(newRow, newCol) && !visited[newRow][newCol]) { + dfs(newRow, newCol, str + board[newRow][newCol], visited); + } + } + visited[row][col] = false; + } + + return res; +}; From 7ca169fc966fe175644232c7d1d24dbfdde9f06d Mon Sep 17 00:00:00 2001 From: jun0811 Date: Sat, 16 Aug 2025 08:18:01 +0900 Subject: [PATCH 6/6] coin-change --- coin-change/jun0811.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 coin-change/jun0811.js diff --git a/coin-change/jun0811.js b/coin-change/jun0811.js new file mode 100644 index 000000000..2253530e8 --- /dev/null +++ b/coin-change/jun0811.js @@ -0,0 +1,13 @@ +var coinChange = function(coins, amount) { + if(amount == 0) return 0 + + const dp = [0, ...new Array(amount).fill(amount+1)] + + for (const coin of coins) { + for (let i = coin; i <=amount; i++) { + dp[i] = Math.min(dp[i], dp[i-coin] + 1) + } + } + + return dp[amount] < amount+1 ? dp[amount] : -1 +};