From cb17d6c30290b9101630745ea7aa2ff9890effbd Mon Sep 17 00:00:00 2001 From: Jennifer Lee Date: Fri, 26 Jun 2026 23:20:06 -0600 Subject: [PATCH 1/2] week01 solutions --- contains-duplicate/hyunpill3.java | 12 ++++++++++ house-robber/hyunpill3.java | 15 ++++++++++++ longest-consecutive-sequence/hyunpill3.java | 26 +++++++++++++++++++++ top-k-frequent-elements/hyunpill3.java | 17 ++++++++++++++ two-sum/hyunpill3.java | 12 ++++++++++ 5 files changed, 82 insertions(+) create mode 100644 contains-duplicate/hyunpill3.java create mode 100644 house-robber/hyunpill3.java create mode 100644 longest-consecutive-sequence/hyunpill3.java create mode 100644 top-k-frequent-elements/hyunpill3.java create mode 100644 two-sum/hyunpill3.java diff --git a/contains-duplicate/hyunpill3.java b/contains-duplicate/hyunpill3.java new file mode 100644 index 0000000000..60f499dd21 --- /dev/null +++ b/contains-duplicate/hyunpill3.java @@ -0,0 +1,12 @@ +class Solution { + public boolean containsDuplicate(int[] nums) { + HashSet set = new HashSet<>(); + for (int num : nums) { + if (set.contains(num)) { + return true; + } + set.add(num); + } + return false; + } +} \ No newline at end of file diff --git a/house-robber/hyunpill3.java b/house-robber/hyunpill3.java new file mode 100644 index 0000000000..25439edcef --- /dev/null +++ b/house-robber/hyunpill3.java @@ -0,0 +1,15 @@ +class Solution { + public int rob(int[] nums) { + int next = 0; + int next2 = 0; + + for (int num : nums) { + int current = Math.max(next, next2 + num); + + next2 = next; + next = current; + } + + return next; + } +} \ No newline at end of file diff --git a/longest-consecutive-sequence/hyunpill3.java b/longest-consecutive-sequence/hyunpill3.java new file mode 100644 index 0000000000..23551c2c70 --- /dev/null +++ b/longest-consecutive-sequence/hyunpill3.java @@ -0,0 +1,26 @@ +class Solution { + public int longestConsecutive(int[] nums) { + Set set = new HashSet<>(); + for (int num : nums) { + set.add(num); + } + + int res = 0; + + for (int num : set) { + if (!set.contains(num - 1)) { + int current = num; + int count = 1; + + while (set.contains(current + 1)) { + current++; + count++; + } + + res = Math.max(res, count); + } + } + + return res; + } +} \ No newline at end of file diff --git a/top-k-frequent-elements/hyunpill3.java b/top-k-frequent-elements/hyunpill3.java new file mode 100644 index 0000000000..c5af6eb936 --- /dev/null +++ b/top-k-frequent-elements/hyunpill3.java @@ -0,0 +1,17 @@ +class Solution { + public int[] topKFrequent(int[] nums, int k) { + List list = new ArrayList<>(); + Arrays.stream(nums) + .boxed() + .collect(Collectors.groupingBy(x -> x)) + .entrySet() + .stream() + .sorted(Map.Entry.comparingByValue((o1, o2) -> Integer.compare(o2.size(), o1.size()))) + .forEachOrdered(x -> { + if (list.size() < k) + list.add(x.getKey()); + }); + + return list.stream().mapToInt(Integer::intValue).toArray(); + } +} \ No newline at end of file diff --git a/two-sum/hyunpill3.java b/two-sum/hyunpill3.java new file mode 100644 index 0000000000..cc8f0cf6d6 --- /dev/null +++ b/two-sum/hyunpill3.java @@ -0,0 +1,12 @@ +class Solution { + public int[] twoSum(int[] nums, int target) { + HashMap map = new HashMap<>(); + for (int i = 0; i < nums.length; i++) { + int num2 = target - nums[i]; + if (map.containsKey(num2)) { + return new int[] { map.get(num2), i}; + } + map.put(nums[i], i) + } + } +} \ No newline at end of file From feddaa5cc8d9a3d4ed79a6e5aeeb0869daddaa1c Mon Sep 17 00:00:00 2001 From: Jennifer Lee Date: Fri, 26 Jun 2026 23:31:06 -0600 Subject: [PATCH 2/2] WEEK01 fixing missing newline --- contains-duplicate/hyunpill3.java | 2 +- house-robber/hyunpill3.java | 2 +- longest-consecutive-sequence/hyunpill3.java | 2 +- top-k-frequent-elements/hyunpill3.java | 2 +- two-sum/hyunpill3.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/contains-duplicate/hyunpill3.java b/contains-duplicate/hyunpill3.java index 60f499dd21..9704e64f02 100644 --- a/contains-duplicate/hyunpill3.java +++ b/contains-duplicate/hyunpill3.java @@ -9,4 +9,4 @@ public boolean containsDuplicate(int[] nums) { } return false; } -} \ No newline at end of file +} diff --git a/house-robber/hyunpill3.java b/house-robber/hyunpill3.java index 25439edcef..d475ae668c 100644 --- a/house-robber/hyunpill3.java +++ b/house-robber/hyunpill3.java @@ -12,4 +12,4 @@ public int rob(int[] nums) { return next; } -} \ No newline at end of file +} diff --git a/longest-consecutive-sequence/hyunpill3.java b/longest-consecutive-sequence/hyunpill3.java index 23551c2c70..699acf08e7 100644 --- a/longest-consecutive-sequence/hyunpill3.java +++ b/longest-consecutive-sequence/hyunpill3.java @@ -23,4 +23,4 @@ public int longestConsecutive(int[] nums) { return res; } -} \ No newline at end of file +} diff --git a/top-k-frequent-elements/hyunpill3.java b/top-k-frequent-elements/hyunpill3.java index c5af6eb936..73c49fa568 100644 --- a/top-k-frequent-elements/hyunpill3.java +++ b/top-k-frequent-elements/hyunpill3.java @@ -14,4 +14,4 @@ public int[] topKFrequent(int[] nums, int k) { return list.stream().mapToInt(Integer::intValue).toArray(); } -} \ No newline at end of file +} diff --git a/two-sum/hyunpill3.java b/two-sum/hyunpill3.java index cc8f0cf6d6..8096ab286b 100644 --- a/two-sum/hyunpill3.java +++ b/two-sum/hyunpill3.java @@ -9,4 +9,4 @@ public int[] twoSum(int[] nums, int target) { map.put(nums[i], i) } } -} \ No newline at end of file +}