From 57a55c38c75a3cac138e51a318bf28e06acd9b0b Mon Sep 17 00:00:00 2001 From: hyeok Date: Wed, 26 Nov 2025 16:49:00 +0900 Subject: [PATCH 1/7] encode-and-decode solution --- encode-and-decode-strings/dylan-jung.cpp | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 encode-and-decode-strings/dylan-jung.cpp diff --git a/encode-and-decode-strings/dylan-jung.cpp b/encode-and-decode-strings/dylan-jung.cpp new file mode 100644 index 0000000000..86d981b36c --- /dev/null +++ b/encode-and-decode-strings/dylan-jung.cpp @@ -0,0 +1,25 @@ +class Codec { + public: + string encode(vector& strs) { + string result; + for (const string& s : strs) { + result += to_string(s.size()) + "#" + s; + } + return result; + } + + vector decode(string s) { + vector result; + int i = 0; + while (i < s.size()) { + int j = i; + while (s[j] != '#') j++; + int length = stoi(s.substr(i, j - i)); + string cur = s.substr(j + 1, length); + result.push_back(cur); + i = j + 1 + length; + } + return result; + } + }; + \ No newline at end of file From 0a5dd4a2829e649bd9ca2c02acb87583f23dbc8b Mon Sep 17 00:00:00 2001 From: hyeok Date: Wed, 3 Dec 2025 14:25:56 +0900 Subject: [PATCH 2/7] merge two sorted list sol --- merge-two-sorted-lists/dylan-jung.cpp | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 merge-two-sorted-lists/dylan-jung.cpp diff --git a/merge-two-sorted-lists/dylan-jung.cpp b/merge-two-sorted-lists/dylan-jung.cpp new file mode 100644 index 0000000000..b7945e6c4d --- /dev/null +++ b/merge-two-sorted-lists/dylan-jung.cpp @@ -0,0 +1,32 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode() : val(0), next(nullptr) {} + * ListNode(int x) : val(x), next(nullptr) {} + * ListNode(int x, ListNode *next) : val(x), next(next) {} + * }; + */ +class Solution { +public: + ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { + ListNode dummy; + ListNode* tail = &dummy; + + while (list1 && list2) { + if (list1->val < list2->val) { + tail->next = list1; + list1 = list1->next; + } else { + tail->next = list2; + list2 = list2->next; + } + tail = tail->next; + } + + tail->next = list1 ? list1 : list2; + + return dummy.next; + } +}; From de1ca4331e6cd2baa9b273de1e0fff0393666f6d Mon Sep 17 00:00:00 2001 From: hyeok Date: Wed, 3 Dec 2025 14:27:10 +0900 Subject: [PATCH 3/7] max depth of bin tree sol --- maximum-depth-of-binary-tree/dylan-jung.cpp | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 maximum-depth-of-binary-tree/dylan-jung.cpp diff --git a/maximum-depth-of-binary-tree/dylan-jung.cpp b/maximum-depth-of-binary-tree/dylan-jung.cpp new file mode 100644 index 0000000000..d507899027 --- /dev/null +++ b/maximum-depth-of-binary-tree/dylan-jung.cpp @@ -0,0 +1,25 @@ +/** + * Definition for a binary tree node. + * struct TreeNode { + * int val; + * TreeNode *left; + * TreeNode *right; + * TreeNode() : val(0), left(nullptr), right(nullptr) {} + * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} + * }; + */ +class Solution { +public: + int dfs(TreeNode* root, int depth) { + int ret = depth; + if(root->left) ret = max(ret, dfs(root->left, depth+1)); + if(root->right) ret = max(ret, dfs(root->right, depth+1)); + return ret; + } + + int maxDepth(TreeNode* root) { + if(!root) return 0; + return dfs(root, 1); + } +}; From eed5169592191b67ad48d5b1804b6f8a1280c408 Mon Sep 17 00:00:00 2001 From: hyeok Date: Wed, 3 Dec 2025 14:27:58 +0900 Subject: [PATCH 4/7] find min in rotated arr --- .../dylan-jung.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 find-minimum-in-rotated-sorted-array/dylan-jung.cpp diff --git a/find-minimum-in-rotated-sorted-array/dylan-jung.cpp b/find-minimum-in-rotated-sorted-array/dylan-jung.cpp new file mode 100644 index 0000000000..44e996ba37 --- /dev/null +++ b/find-minimum-in-rotated-sorted-array/dylan-jung.cpp @@ -0,0 +1,23 @@ +class Solution { +public: + int findMin(vector& nums) { + int l = 0; int r = nums.size() - 1; + int min = -10000; + if(nums[l] <= nums[r]) return nums[0]; // ordered case + while(l <= r) { + int mid = (l+r)/2; + if(nums[l] > nums[mid]) { + min = mid; + r = mid; + } + else if(nums[mid] > nums[r]) { + min = mid+1; + l = mid+1; + } + else { + break; + } + } + return nums[min]; + } +}; From df49ade1105a7cfc9ffad421007ad91a8fcee75d Mon Sep 17 00:00:00 2001 From: hyeok Date: Wed, 3 Dec 2025 14:28:41 +0900 Subject: [PATCH 5/7] word search sol --- word-search/dylan-jung.cpp | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 word-search/dylan-jung.cpp diff --git a/word-search/dylan-jung.cpp b/word-search/dylan-jung.cpp new file mode 100644 index 0000000000..9520edddf8 --- /dev/null +++ b/word-search/dylan-jung.cpp @@ -0,0 +1,40 @@ +class Solution { +public: + vector> g_board; + int m, n; + int dx[4] = { -1, 1, 0, 0 }; + int dy[4] = { 0, 0, -1, 1 }; + bool visited[6][6]; + + bool hasWord(string word, int idx, int r, int c) { + if(idx >= word.size()) return true; + if(!(0 <= r && r < n && 0 <= c && c < m)) return false; + if(g_board[r][c] != word[idx]) return false; + if(visited[r][c]) return false; + visited[r][c] = true; + // cout << r << " " << c << " " << word[idx] << "\n"; + for(int i = 0; i < 4; i++) { + int nr = r + dx[i]; + int nc = c + dy[i]; + if(hasWord(word, idx+1, nr, nc)) + return true; + } + visited[r][c] = false; + return false; + } + + bool exist(vector>& board, string word) { + g_board = board; + n = board.size(); + m = board[0].size(); + for(int i = 0; i < n; i++) { + for(int j = 0; j < m; j++) { + if(g_board[i][j] == word[0]) { + fill(&visited[0][0], &visited[0][0]+36, false); + if(hasWord(word, 0, i, j)) return true; + } + } + } + return false; + } +}; From 12aee5348f82f4bd9491f28a39232e0f2e05dbc5 Mon Sep 17 00:00:00 2001 From: hyeok Date: Wed, 3 Dec 2025 14:29:37 +0900 Subject: [PATCH 6/7] con chnage sol --- coin-change/dylan-jung.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 coin-change/dylan-jung.cpp diff --git a/coin-change/dylan-jung.cpp b/coin-change/dylan-jung.cpp new file mode 100644 index 0000000000..6c81b9a695 --- /dev/null +++ b/coin-change/dylan-jung.cpp @@ -0,0 +1,28 @@ +class Solution { +public: + long dp[10001]; + int coinChange(vector& coins, int amount) { + long INF = (long)1 << 31; + fill(dp, dp+10001, INF); + + for(int& item: coins) { + if(item > 10000) continue; + dp[item] = 1; + } + + for(int i = 1; i <= amount; i++) { + for(int& item: coins) { + int j = i - item; + if(j > 0 && dp[j] != -1) { + dp[i] = min(dp[j] + 1, dp[i]); + } + } + } + + if(dp[amount] == INF) { + if(amount == 0) return 0; + else return -1; + } + return dp[amount]; + } +}; From 487825662d39dfc5da7700652eea3636e9ad281d Mon Sep 17 00:00:00 2001 From: hyeok Date: Wed, 3 Dec 2025 14:41:39 +0900 Subject: [PATCH 7/7] line brak --- encode-and-decode-strings/dylan-jung.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/encode-and-decode-strings/dylan-jung.cpp b/encode-and-decode-strings/dylan-jung.cpp index 86d981b36c..451e72d25e 100644 --- a/encode-and-decode-strings/dylan-jung.cpp +++ b/encode-and-decode-strings/dylan-jung.cpp @@ -22,4 +22,3 @@ class Codec { return result; } }; - \ No newline at end of file