From 861bfbcb2146f074487b4a103eaac23dd58880d4 Mon Sep 17 00:00:00 2001 From: hyeok Date: Tue, 18 Nov 2025 09:18:32 +0900 Subject: [PATCH 1/6] valid anagram solution --- valid-anagram/dylan-jung.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 valid-anagram/dylan-jung.cpp diff --git a/valid-anagram/dylan-jung.cpp b/valid-anagram/dylan-jung.cpp new file mode 100644 index 0000000000..3d5d74140d --- /dev/null +++ b/valid-anagram/dylan-jung.cpp @@ -0,0 +1,14 @@ +class Solution { +public: + bool isAnagram(string s, string t) { + if(s.size() != t.size()) return false; + unordered_map m1; + unordered_map m2; + for(char c: s) m1[c]++; + for(char c: t) m2[c]++; + for(auto const& item: m1) { + if(m2[item.first] != item.second) return false; + } + return true; + } +}; From a554bbd59cfd6a8412f399b67b307a7ccc461cc5 Mon Sep 17 00:00:00 2001 From: hyeok Date: Fri, 21 Nov 2025 15:41:26 +0900 Subject: [PATCH 2/6] climbing-stairs solutions --- climbing-stairs/dylan-jung.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 climbing-stairs/dylan-jung.cpp diff --git a/climbing-stairs/dylan-jung.cpp b/climbing-stairs/dylan-jung.cpp new file mode 100644 index 0000000000..4262dc68df --- /dev/null +++ b/climbing-stairs/dylan-jung.cpp @@ -0,0 +1,11 @@ +class Solution { +int dp[45] = { 0 }; +public: + int climbStairs(int n) { + dp[0] = 1; + if(n > 1) dp[1] = 2; + for(int i = 2; i < n; i++) + dp[i] = dp[i-1] + dp[i-2]; + return dp[n-1]; + } +}; From 5527f2b938774aa2c316097e92fa2592a91eeb48 Mon Sep 17 00:00:00 2001 From: hyeok Date: Fri, 21 Nov 2025 15:53:37 +0900 Subject: [PATCH 3/6] product of array except self solution --- product-of-array-except-self/dylan-jung.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 product-of-array-except-self/dylan-jung.cpp diff --git a/product-of-array-except-self/dylan-jung.cpp b/product-of-array-except-self/dylan-jung.cpp new file mode 100644 index 0000000000..7c0cfc0931 --- /dev/null +++ b/product-of-array-except-self/dylan-jung.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + vector productExceptSelf(vector& nums) { + vector ans; + ans.resize(nums.size(), 1); + int p = 1; + int idx = nums.size()-1; + for(auto it = nums.rbegin(); it != nums.rend(); it++, idx--) { + ans[idx] *= p; + p *= *it; // 마지막 건 그냥 무시 + } + p = 1; + idx = 0; + for(auto it = nums.begin(); it != nums.end(); it++, idx++) { + ans[idx] *= p; + p *= *it; + } + return ans; + } +}; From 076b11c8ea95cebc83869369e883a50a154c2441 Mon Sep 17 00:00:00 2001 From: hyeok Date: Fri, 21 Nov 2025 15:54:25 +0900 Subject: [PATCH 4/6] 3sum solution --- 3sum/dylan-jung.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 3sum/dylan-jung.cpp diff --git a/3sum/dylan-jung.cpp b/3sum/dylan-jung.cpp new file mode 100644 index 0000000000..d0fa834b99 --- /dev/null +++ b/3sum/dylan-jung.cpp @@ -0,0 +1,29 @@ +class Solution { +public: + vector> threeSum(vector& nums) { + sort(nums.begin(), nums.end()); + vector> result; + for(int a = 0; a < nums.size()-2; a++) { + if (a > 0 && nums[a] == nums[a - 1]) continue; + int b = a + 1; + int c = nums.size() - 1; + while(b < c) { + if(nums[a] + nums[b] + nums[c] < 0) { + b++; + } + else if (nums[a] + nums[b] + nums[c] > 0) { + c--; + } + else { + result.push_back({nums[a], nums[b], nums[c]}); + b++; + c--; + while (b < c && nums[b] == nums[b - 1]) b++; + while (b < c && nums[c] == nums[c + 1]) c--; + } + } + } + + return result; + } +}; From 40761bdb14b487621897451462129e842876e6fa Mon Sep 17 00:00:00 2001 From: hyeok Date: Fri, 21 Nov 2025 15:55:15 +0900 Subject: [PATCH 5/6] validate-bin-search-tree --- validate-binary-search-tree/dylan-jung.cpp | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 validate-binary-search-tree/dylan-jung.cpp diff --git a/validate-binary-search-tree/dylan-jung.cpp b/validate-binary-search-tree/dylan-jung.cpp new file mode 100644 index 0000000000..b8e31ac734 --- /dev/null +++ b/validate-binary-search-tree/dylan-jung.cpp @@ -0,0 +1,29 @@ +/** + * 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: + bool dfs(TreeNode* root, long minVal, long maxVal) { + if(!(minVal < root->val && root->val < maxVal)) return false; + bool isValid = true; + if(root->left) { + isValid = isValid && dfs(root->left, minVal, min((long)root->val, maxVal)); + } + if(root->right) { + isValid = isValid && dfs(root->right, max((long)root->val, minVal), maxVal); + } + return isValid; + } + + bool isValidBST(TreeNode* root) { + return dfs(root, -(1l << 32), 1l << 32); + } +}; From 1ae2729504c9d56c9ed010b2200a22cffbbbe220 Mon Sep 17 00:00:00 2001 From: hyeok Date: Sun, 23 Nov 2025 00:54:17 +0900 Subject: [PATCH 6/6] Fix: validate bin search tree --- validate-binary-search-tree/dylan-jung.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/validate-binary-search-tree/dylan-jung.cpp b/validate-binary-search-tree/dylan-jung.cpp index b8e31ac734..a454f9ca63 100644 --- a/validate-binary-search-tree/dylan-jung.cpp +++ b/validate-binary-search-tree/dylan-jung.cpp @@ -9,21 +9,22 @@ * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ - class Solution { +class Solution { public: bool dfs(TreeNode* root, long minVal, long maxVal) { if(!(minVal < root->val && root->val < maxVal)) return false; bool isValid = true; - if(root->left) { - isValid = isValid && dfs(root->left, minVal, min((long)root->val, maxVal)); + if (root->left) { + isValid = isValid && dfs(root->left, minVal, root->val); } - if(root->right) { - isValid = isValid && dfs(root->right, max((long)root->val, minVal), maxVal); + if (root->right) { + isValid = isValid && dfs(root->right, root->val, maxVal); } return isValid; } bool isValidBST(TreeNode* root) { + if(!root) return true; return dfs(root, -(1l << 32), 1l << 32); } };