From 19d0cf151e270c249f4c0cfa4f9094a8fe7bf729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Fri, 14 Nov 2025 08:20:44 +0000 Subject: [PATCH 1/6] contains-duplicate solution --- contains-duplicate/hyunolike.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 contains-duplicate/hyunolike.java diff --git a/contains-duplicate/hyunolike.java b/contains-duplicate/hyunolike.java new file mode 100644 index 000000000..ce6fae0db --- /dev/null +++ b/contains-duplicate/hyunolike.java @@ -0,0 +1,23 @@ +class Solution { + public boolean containsDuplicate(int[] nums) { + // 중복 체크 + // 각 요소 순환 + + // 1. 배열 순환 + // 2. 2 이상 true 체크 + + // 자료구조 Map 사용 + HashMap map = new HashMap<>(); + + for (int num : nums) { + //System.out.println(num); + if (map.containsKey(num)) { + return true; + } + + map.put(Integer.valueOf(num), Integer.valueOf(num)); + } + + return false; + } +} \ No newline at end of file From d36416a11c051c325bc758cbc8719e99be4a495e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Fri, 14 Nov 2025 08:21:56 +0000 Subject: [PATCH 2/6] two sum solution --- two-sum/hyunolike.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 two-sum/hyunolike.java diff --git a/two-sum/hyunolike.java b/two-sum/hyunolike.java new file mode 100644 index 000000000..c6b5ad405 --- /dev/null +++ b/two-sum/hyunolike.java @@ -0,0 +1,20 @@ +class Solution { + public int[] twoSum(int[] nums, int target) { + // 모든 경우의 수 체크 + + // 결과값 + int[] result = null; + + // 순회 + for(int i = 0; i < nums.length; i++){ + for(int j = i+1; j < nums.length; j++) { + int sum = nums[i] + nums[j]; + if(sum == target) { + result = new int[]{i, j}; + } + } + } + + return result; + } +} \ No newline at end of file From 309f321ae16ed414fd3505d1b7be331046d56e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Fri, 14 Nov 2025 08:22:51 +0000 Subject: [PATCH 3/6] top-k-frequent-elements solution --- top-k-frequent-elements/hyunolike.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 top-k-frequent-elements/hyunolike.java diff --git a/top-k-frequent-elements/hyunolike.java b/top-k-frequent-elements/hyunolike.java new file mode 100644 index 000000000..9cc5d732a --- /dev/null +++ b/top-k-frequent-elements/hyunolike.java @@ -0,0 +1,23 @@ +class Solution { + public int[] topKFrequent(int[] nums, int k) { + Map counter = new HashMap<>(); + for (int n : nums) { + counter.put(n, counter.getOrDefault(n, 0) + 1); + } + + PriorityQueue> heap = new PriorityQueue<>( + (a, b) -> Integer.compare(b.getValue(), a.getValue()) + ); + + for (Map.Entry entry : counter.entrySet()) { + heap.offer(entry); + } + + int[] res = new int[k]; + for(int i = 0; i < k; i++) { + res[i] = Objects.requireNonNull(heap.poll()).getKey(); + } + + return res; + } +} \ No newline at end of file From 21339d9363dbcb00397cab13d01e63f4dd285ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Fri, 14 Nov 2025 08:23:57 +0000 Subject: [PATCH 4/6] longest-consecutive-sequence solution --- longest-consecutive-sequence/hyunolike.java | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 longest-consecutive-sequence/hyunolike.java diff --git a/longest-consecutive-sequence/hyunolike.java b/longest-consecutive-sequence/hyunolike.java new file mode 100644 index 000000000..ea82c4e3e --- /dev/null +++ b/longest-consecutive-sequence/hyunolike.java @@ -0,0 +1,28 @@ +class Solution { + public int longestConsecutive(int[] nums) { + // 연속된 숫자 길이 파악 + // 연속된 거 어떻게? + if(nums.length == 0 || nums == null) return 0; + + int result = 0; + + Arrays.sort(nums); + + int maxLen = 1; + int len = 1; + + for(int i = 1; i < nums.length; i++) { + // 중복 체크 + if(nums[i] == nums[i-1]) { + continue; + }else if(nums[i] == nums[i-1] + 1) { + len++; + maxLen = Math.max(maxLen, len); + }else{ + len = 1; + } + } + + return maxLen; + } +} \ No newline at end of file From 1b7bc6ee27a941e09b089a684ca6c086f028b762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Fri, 14 Nov 2025 08:24:32 +0000 Subject: [PATCH 5/6] house-robber solution --- house-robber/hyunolike.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 house-robber/hyunolike.java diff --git a/house-robber/hyunolike.java b/house-robber/hyunolike.java new file mode 100644 index 000000000..a9a396a46 --- /dev/null +++ b/house-robber/hyunolike.java @@ -0,0 +1,14 @@ +class Solution { + public int rob(int[] nums) { + if (nums.length == 0) return 0; + + int prev1 = 0; + int prev2 = 0; + for(int num : nums) { + int tmp = prev1; + prev1 = Math.max(prev2 + num, prev1); + prev2 = tmp; + } + return prev1; + } +} \ No newline at end of file From a0077906024107c120bc7e92ccddc0c2ef3424a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=ED=98=84=ED=98=B8=20Hyunho=20Jang?= Date: Fri, 14 Nov 2025 13:56:25 +0000 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20=EA=B9=83=ED=97=88=EB=B8=8C=20?= =?UTF-8?q?=EC=97=91=EC=85=98=20=EC=9D=B4=EC=8A=88=20-=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EB=A7=88=EC=A7=80=EB=A7=89=20=ED=96=89=20=EC=A4=84?= =?UTF-8?q?=EB=B0=94=EA=BF=88=20=EA=B2=80=EC=A6=9D=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contains-duplicate/hyunolike.java | 2 +- house-robber/hyunolike.java | 2 +- longest-consecutive-sequence/hyunolike.java | 2 +- top-k-frequent-elements/hyunolike.java | 2 +- two-sum/hyunolike.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/contains-duplicate/hyunolike.java b/contains-duplicate/hyunolike.java index ce6fae0db..215383244 100644 --- a/contains-duplicate/hyunolike.java +++ b/contains-duplicate/hyunolike.java @@ -20,4 +20,4 @@ public boolean containsDuplicate(int[] nums) { return false; } -} \ No newline at end of file +} diff --git a/house-robber/hyunolike.java b/house-robber/hyunolike.java index a9a396a46..61593d932 100644 --- a/house-robber/hyunolike.java +++ b/house-robber/hyunolike.java @@ -11,4 +11,4 @@ public int rob(int[] nums) { } return prev1; } -} \ No newline at end of file +} diff --git a/longest-consecutive-sequence/hyunolike.java b/longest-consecutive-sequence/hyunolike.java index ea82c4e3e..ee44251a0 100644 --- a/longest-consecutive-sequence/hyunolike.java +++ b/longest-consecutive-sequence/hyunolike.java @@ -25,4 +25,4 @@ public int longestConsecutive(int[] nums) { return maxLen; } -} \ No newline at end of file +} diff --git a/top-k-frequent-elements/hyunolike.java b/top-k-frequent-elements/hyunolike.java index 9cc5d732a..688928eeb 100644 --- a/top-k-frequent-elements/hyunolike.java +++ b/top-k-frequent-elements/hyunolike.java @@ -20,4 +20,4 @@ public int[] topKFrequent(int[] nums, int k) { return res; } -} \ No newline at end of file +} diff --git a/two-sum/hyunolike.java b/two-sum/hyunolike.java index c6b5ad405..ba6480a72 100644 --- a/two-sum/hyunolike.java +++ b/two-sum/hyunolike.java @@ -17,4 +17,4 @@ public int[] twoSum(int[] nums, int target) { return result; } -} \ No newline at end of file +}