From 158003b207da6d0577df28a818eaa55478062d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Sun, 23 Nov 2025 01:08:49 +0000 Subject: [PATCH 1/5] 3sum solution --- 3sum/hyunolike.java | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 3sum/hyunolike.java diff --git a/3sum/hyunolike.java b/3sum/hyunolike.java new file mode 100644 index 000000000..dbbb2329e --- /dev/null +++ b/3sum/hyunolike.java @@ -0,0 +1,41 @@ +class Solution { + public List> threeSum(int[] nums) { + List> result = new ArrayList<>(); + + int n = nums.length; + if (n < 3) return result; + + Arrays.sort(nums); + + for(int i = 0; i < n - 2; i++) { + if(i > 0 && nums[i] == nums[i-1]) continue; + + int left = i + 1; + int right = n - 1; + + while(left < right) { + int sum = nums[i] + nums[left] + nums[right]; + + if(sum < 0){ + left++; + } + else if(sum > 0) { + right --; + } + else { + // sum == 0 → 조합 하나 찾음 + result.add(Arrays.asList(nums[i], nums[left], nums[right])); + + // left, right 중복값 스킵 + int leftVal = nums[left]; + int rightVal = nums[right]; + + while (left < right && nums[left] == leftVal) left++; + while (left < right && nums[right] == rightVal) right--; + } + } + } + + return result; + } +} From 23f97a962e682910a0aadcbf7094d7aa37302541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Sun, 23 Nov 2025 01:09:37 +0000 Subject: [PATCH 2/5] climbing stairs solution --- climbing-stairs/hyunolike.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 climbing-stairs/hyunolike.java diff --git a/climbing-stairs/hyunolike.java b/climbing-stairs/hyunolike.java new file mode 100644 index 000000000..1d4484a05 --- /dev/null +++ b/climbing-stairs/hyunolike.java @@ -0,0 +1,20 @@ +class Solution { + public int climbStairs(int n) { + + // 경우의 수 하기 >> 피보나치? + // ways(n) = ways(n-1) + ways(n-2) + + if(n == 1) return 1; + if(n == 2) return 2; + + int[] dp = new int[n+1]; + dp[1] = 1; + dp[2] = 2; + + for(int i = 3; i <= n; i++) { + dp[i] = dp[i-1] + dp[i-2]; + } + + return dp[n]; + } +} From 326987e0e0c88b4635ffb2c325c13e5a1f5c526e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Sun, 23 Nov 2025 01:10:19 +0000 Subject: [PATCH 3/5] product of array except self solution --- product-of-array-except-self/hyunolike.java | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 product-of-array-except-self/hyunolike.java diff --git a/product-of-array-except-self/hyunolike.java b/product-of-array-except-self/hyunolike.java new file mode 100644 index 000000000..d30ee101d --- /dev/null +++ b/product-of-array-except-self/hyunolike.java @@ -0,0 +1,23 @@ +class Solution { + public int[] productExceptSelf(int[] nums) { + + int n = nums.length; + int[] ans = new int[n]; + + // 1. 왼족 곱 + int left = 1; + for(int i = 0; i < n; i++) { + ans[i] = left; + left *= nums[i]; + } + + // 2. 오른쪽 곱 + int right = 1; + for(int i = n-1; i >=0; i--){ + ans[i] *= right; + right *= nums[i]; + } + + return ans; + } +} From cedd6d9ca3e3552103baa71aba9e0f1c5f2fc5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Sun, 23 Nov 2025 01:11:06 +0000 Subject: [PATCH 4/5] valid anagram solution --- valid-anagram/hyunolike.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 valid-anagram/hyunolike.java diff --git a/valid-anagram/hyunolike.java b/valid-anagram/hyunolike.java new file mode 100644 index 000000000..0a4aa1304 --- /dev/null +++ b/valid-anagram/hyunolike.java @@ -0,0 +1,14 @@ +class Solution { + public boolean isAnagram(String s, String t) { + // 각 문자열 배열 char[] 로 변환 + // 그리고 비교 (?) + + char[] sArray = s.toCharArray(); + char[] tArray = t.toCharArray(); + + Arrays.sort(sArray); + Arrays.sort(tArray); + + return Arrays.equals(sArray, tArray); + } +} From 50f2b9d32a6c8b3d098cd77c338560e9aca6f4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Sun, 23 Nov 2025 01:23:37 +0000 Subject: [PATCH 5/5] validate binary search tree solution --- validate-binary-search-tree/hyunolike.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 validate-binary-search-tree/hyunolike.java diff --git a/validate-binary-search-tree/hyunolike.java b/validate-binary-search-tree/hyunolike.java new file mode 100644 index 000000000..f99f53b42 --- /dev/null +++ b/validate-binary-search-tree/hyunolike.java @@ -0,0 +1,31 @@ +/** + * 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 { + public boolean isValidBST(TreeNode root) { + return isValid(root, null, null); + } + + private boolean isValid(TreeNode node, Integer min, Integer max) { + if (node == null) { + return true; + } + + if (min != null && node.val <= min) return false; + if (max != null && node.val >= max) return false; + + return isValid(node.left, min, node.val) && isValid(node.right, node.val, max); + } +}