From 1361bfa29d7a410b06c3324548a3bb61e496eee3 Mon Sep 17 00:00:00 2001 From: chjung99 Date: Sun, 9 Nov 2025 14:45:36 +0900 Subject: [PATCH 1/8] two sum solution --- two-sum/chjung99.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 two-sum/chjung99.java diff --git a/two-sum/chjung99.java b/two-sum/chjung99.java new file mode 100644 index 0000000000..992fbe97b6 --- /dev/null +++ b/two-sum/chjung99.java @@ -0,0 +1,24 @@ +import java.util.*; + +class Solution { + public int[] twoSum(int[] nums, int target) { + HashMap> map = new HashMap(); + for (int i = 0; i < nums.length; i++) { + if (!map.containsKey(nums[i])) { + map.put(nums[i], new ArrayList()); + } + map.get(nums[i]).add(i); + } + + for (Map.Entry> e: map.entrySet()) { + int other = target - e.getKey(); + if (map.containsKey(other)) { + if (e.getKey() == other && map.get(other).size() > 1) { + return new int[]{e.getValue().get(0), e.getValue().get(1)}; + } + return new int[]{e.getValue().get(0), map.get(other).get(0)}; + } + } + return new int[]{}; + } +} \ No newline at end of file From 6279a32c8abe2643f5142ec727e06c877ef65656 Mon Sep 17 00:00:00 2001 From: chjung99 Date: Mon, 10 Nov 2025 21:13:27 +0900 Subject: [PATCH 2/8] =?UTF-8?q?two=20sum=20solution,=20=EA=B0=9C=ED=96=89?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- two-sum/chjung99.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/two-sum/chjung99.java b/two-sum/chjung99.java index 992fbe97b6..7be791c834 100644 --- a/two-sum/chjung99.java +++ b/two-sum/chjung99.java @@ -21,4 +21,4 @@ public int[] twoSum(int[] nums, int target) { } return new int[]{}; } -} \ No newline at end of file +} From 502f628d9ea2a75c0206dd57d633775aaa94bbb2 Mon Sep 17 00:00:00 2001 From: chjung99 Date: Mon, 10 Nov 2025 21:14:11 +0900 Subject: [PATCH 3/8] valid parentheses solution --- valid-parentheses/chjung99.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 valid-parentheses/chjung99.java diff --git a/valid-parentheses/chjung99.java b/valid-parentheses/chjung99.java new file mode 100644 index 0000000000..93520acfb6 --- /dev/null +++ b/valid-parentheses/chjung99.java @@ -0,0 +1,31 @@ +import java.util.*; + +class Solution { + public boolean isValid(String s) { + ArrayDeque stack = new ArrayDeque<>(); + for (int i = 0; i < s.length(); i++){ + if (s.charAt(i) == '(' || s.charAt(i) == '{' || s.charAt(i) == '[' ){ + stack.push(s.charAt(i)); + continue; + } + + if (s.charAt(i) == ')' && !stack.isEmpty() && stack.peek() == '('){ + stack.pop(); + continue; + } + + if (s.charAt(i) == '}' && !stack.isEmpty() && stack.peek() == '{'){ + stack.pop(); + continue; + } + + if (s.charAt(i) == ']' && !stack.isEmpty() && stack.peek() == '['){ + stack.pop(); + continue; + } + return false; + } + return stack.isEmpty(); + + } +} From 1daef1e4f73cffe3e078e3cbef0f0054618e6345 Mon Sep 17 00:00:00 2001 From: chjung99 Date: Mon, 10 Nov 2025 21:15:57 +0900 Subject: [PATCH 4/8] =?UTF-8?q?valid=20parentheses=20solution,=20=EA=B0=9C?= =?UTF-8?q?=ED=96=89=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- valid-parentheses/chjung99.java | 1 + 1 file changed, 1 insertion(+) diff --git a/valid-parentheses/chjung99.java b/valid-parentheses/chjung99.java index 93520acfb6..d63793478a 100644 --- a/valid-parentheses/chjung99.java +++ b/valid-parentheses/chjung99.java @@ -29,3 +29,4 @@ public boolean isValid(String s) { } } + From 6b83238489e006ab5b6ce1459db048e8da20dd81 Mon Sep 17 00:00:00 2001 From: chjung99 Date: Mon, 10 Nov 2025 21:16:45 +0900 Subject: [PATCH 5/8] =?UTF-8?q?two=20sum=20solution,=20=EA=B0=9C=ED=96=89?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- two-sum/chjung99.java | 1 + 1 file changed, 1 insertion(+) diff --git a/two-sum/chjung99.java b/two-sum/chjung99.java index 7be791c834..265ca7a1a3 100644 --- a/two-sum/chjung99.java +++ b/two-sum/chjung99.java @@ -22,3 +22,4 @@ public int[] twoSum(int[] nums, int target) { return new int[]{}; } } + From 881f1588bbe6d4db4aa5b30d810f2dddc981c74f Mon Sep 17 00:00:00 2001 From: chjung99 Date: Wed, 12 Nov 2025 00:03:15 +0900 Subject: [PATCH 6/8] merge-two-sorted-list solution --- merge-two-sorted-lists/chjung99.java | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 merge-two-sorted-lists/chjung99.java diff --git a/merge-two-sorted-lists/chjung99.java b/merge-two-sorted-lists/chjung99.java new file mode 100644 index 0000000000..1820aff51c --- /dev/null +++ b/merge-two-sorted-lists/chjung99.java @@ -0,0 +1,46 @@ +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode() {} + * ListNode(int val) { this.val = val; } + * ListNode(int val, ListNode next) { this.val = val; this.next = next; } + * } + */ +class Solution { + public ListNode mergeTwoLists(ListNode list1, ListNode list2) { + ListNode head = initNode(list1, list2); + ListNode ptr = head; + + while (true){ + if (list1 != null && list2 != null) { + if (list1.val < list2.val) { + ptr.val = list1.val; + list1 = list1.next; + } else { + ptr.val = list2.val; + list2 = list2.next; + } + } + else if (list1 == null && list2 != null) { + ptr.val = list2.val; + list2 = list2.next; + } + else if (list1 != null && list2 == null) { + ptr.val = list1.val; + list1 = list1.next; + } + if (list1 == null && list2 == null) break; + ptr.next = new ListNode(); + ptr = ptr.next; + } + return head; + } + + public ListNode initNode(ListNode list1, ListNode list2) { + if (list1 == null && list2 == null) return null; + return new ListNode(); + } +} + From 366f453927e3d099b2248cabbbedb0d670a349bb Mon Sep 17 00:00:00 2001 From: chjung99 Date: Wed, 12 Nov 2025 21:09:57 +0900 Subject: [PATCH 7/8] climbing-stairs solution --- climbing-stairs/chjung99.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 climbing-stairs/chjung99.java diff --git a/climbing-stairs/chjung99.java b/climbing-stairs/chjung99.java new file mode 100644 index 0000000000..339b84994f --- /dev/null +++ b/climbing-stairs/chjung99.java @@ -0,0 +1,15 @@ +class Solution { + public int climbStairs(int n) { + int[] dp = new int[46]; + dp[0] = 1; + dp[1] = 1; + dp[2] = dp[1] + dp[0]; + dp[3] = dp[2] + dp[1]; + + for (int i = 4; i <= n; i++) { + dp[i] = dp[i-1] + dp[i-2]; + } + return dp[n]; + } +} + From f500b9d9943f616bc449e21fb714d23120122b1a Mon Sep 17 00:00:00 2001 From: chjung99 Date: Thu, 13 Nov 2025 22:46:24 +0900 Subject: [PATCH 8/8] same-tree solution --- same-tree/chjung99.java | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 same-tree/chjung99.java diff --git a/same-tree/chjung99.java b/same-tree/chjung99.java new file mode 100644 index 0000000000..e411431f13 --- /dev/null +++ b/same-tree/chjung99.java @@ -0,0 +1,48 @@ +import java.util.*; + +/** + * Definition for a binary tree node. + * public class TreeNode { + * int val; + * TreeNode left; + * TreeNode right; + * TreeNode() {} + * TreeNode(int val) { this.val = val; } + * TreeNode(int val, TreeNode left, TreeNode right) { + * this.val = val; + * this.left = left; + * this.right = right; + * } + * } + */ +class Solution { + final int NULL_MARKER = Integer.MIN_VALUE; + public boolean isSameTree(TreeNode p, TreeNode q) { + Queue OrderP = new ArrayDeque<>(); + Queue OrderQ = new ArrayDeque<>(); + trevasalTree(p, OrderP); + trevasalTree(q, OrderQ); + + if (OrderP.size() != OrderQ.size()) return false; + + while (!OrderP.isEmpty() && !OrderQ.isEmpty()){ + Integer a = OrderP.poll(); + Integer b = OrderQ.poll(); + if (!a.equals(b)) return false; + } + + return OrderP.isEmpty() && OrderQ.isEmpty(); + } + public void trevasalTree(TreeNode t, Queue queue){ + // System.out.print(t.val+ " "); + if (t == null){ + queue.add(NULL_MARKER); + return; + } + queue.add(t.val); + trevasalTree(t.left, queue); + trevasalTree(t.right, queue); + + } +} +