From b8cd8fccd3f66792527c96adf84b6f9ee7070af0 Mon Sep 17 00:00:00 2001 From: renovizee Date: Sun, 20 Jul 2025 17:42:11 +0900 Subject: [PATCH 1/6] feat: Set up Week 1 problems Adds the initial boilerplate files for the week 1 problems, including: - Contains Duplicate (Easy) - Two Sum (Easy) - Top K Frequent Elements (Medium) - Longest Consecutive Sequence (Medium) - House Robber (Medium) --- contains-duplicate/renovizee.java | 9 +++++++++ house-robber/renovizee.java | 9 +++++++++ longest-consecutive-sequence/renovizee.java | 10 ++++++++++ top-k-frequent-elements/renovizee.java | 10 ++++++++++ two-sum/renovizee.java | 11 +++++++++++ 5 files changed, 49 insertions(+) create mode 100644 contains-duplicate/renovizee.java create mode 100644 house-robber/renovizee.java create mode 100644 longest-consecutive-sequence/renovizee.java create mode 100644 top-k-frequent-elements/renovizee.java create mode 100644 two-sum/renovizee.java diff --git a/contains-duplicate/renovizee.java b/contains-duplicate/renovizee.java new file mode 100644 index 000000000..ce3b62ef2 --- /dev/null +++ b/contains-duplicate/renovizee.java @@ -0,0 +1,9 @@ + +// https://github.com/DaleStudy/leetcode-study/issues/217 +// https://leetcode.com/problems/contains-duplicate/ +class Solution { + public boolean containsDuplicate(int[] nums) { + + return true; + } +} diff --git a/house-robber/renovizee.java b/house-robber/renovizee.java new file mode 100644 index 000000000..85f796d42 --- /dev/null +++ b/house-robber/renovizee.java @@ -0,0 +1,9 @@ + +// https://github.com/DaleStudy/leetcode-study/issues/264 +// https://leetcode.com/problems/house-robber/ +class Solution { + public int rob(int[] nums) { + + return 1; + } +} diff --git a/longest-consecutive-sequence/renovizee.java b/longest-consecutive-sequence/renovizee.java new file mode 100644 index 000000000..a3747e8e6 --- /dev/null +++ b/longest-consecutive-sequence/renovizee.java @@ -0,0 +1,10 @@ + +// https://github.com/DaleStudy/leetcode-study/issues/240 +// https://leetcode.com/problems/longest-consecutive-sequence/ +class Solution { + public int longestConsecutive(int[] nums) { + + return 1; + + } +} diff --git a/top-k-frequent-elements/renovizee.java b/top-k-frequent-elements/renovizee.java new file mode 100644 index 000000000..214c3d817 --- /dev/null +++ b/top-k-frequent-elements/renovizee.java @@ -0,0 +1,10 @@ + +// https://github.com/DaleStudy/leetcode-study/issues/237 +// https://leetcode.com/problems/top-k-frequent-elements/ +class Solution { + public int[] topKFrequent(int[] nums, int k) { + int[] result = {1, 2, 3}; + + return result; + } +} diff --git a/two-sum/renovizee.java b/two-sum/renovizee.java new file mode 100644 index 000000000..563c94b44 --- /dev/null +++ b/two-sum/renovizee.java @@ -0,0 +1,11 @@ + +// https://github.com/DaleStudy/leetcode-study/issues/219 +// https://leetcode.com/problems/two-sum/description/ +class Solution { + public int[] twoSum(int[] nums, int target) { + int[] result = {11, 2}; + + return result; + + } +} From 0be02516ac395793b75426f5022478f8e0de31ca Mon Sep 17 00:00:00 2001 From: renovizee Date: Fri, 25 Jul 2025 21:39:24 +0900 Subject: [PATCH 2/6] feat(leetcode/1): Solve Two Sum (Easy) --- two-sum/renovizee.java | 51 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/two-sum/renovizee.java b/two-sum/renovizee.java index 563c94b44..1b9a628c1 100644 --- a/two-sum/renovizee.java +++ b/two-sum/renovizee.java @@ -1,11 +1,60 @@ +import java.util.HashMap; +import java.util.Map; +// tag renovizee 1week // https://github.com/DaleStudy/leetcode-study/issues/219 // https://leetcode.com/problems/two-sum/description/ + +// #요구사항 요약 +// 1. int[] nums와 int target이 주어진다. +// 2. nums의 두 수의 합이 target과 같은 int[] index를 리턴한다. (순서 상관 x) +// 3. 똑같은 원소를 두번 사용하지 못하고, 정확히 하나의 정답만 있다. + class Solution { + // Solv2: map + // 시간복잡도 : O(n) + // 공간복잡도 : O(n) public int[] twoSum(int[] nums, int target) { - int[] result = {11, 2}; + Map map = new HashMap<>(); + int[] result = new int[2]; + for (int i = 0; i < nums.length; i++) { + map.put(nums[i], i); + } + for (int i = 0; i < nums.length; i++) { + int key = target - nums[i]; + if (map.containsKey(key) && map.get(key) != i) { + result[0] = i; + result[1] = map.get(key); + } + } return result; } +//------------------------------------------------------------------------------------------------------------- +// Solv1: Brute Force +// 시간복잡도 : O(n^2) +// 공간복잡도 : O(1) +// public int[] twoSum(int[] nums, int target) { +// int size = nums.length; +// for(int i = 0; i < size - 1; i++) { +// for(int j = i+1; j < size; j++) { +// if(target == (nums[i] + nums[j])){ +// return new int[]{i,j}; +// } +// } +// } +// return new int[]{}; +// } + + +// 1) ==: 두 값이 같은지 비교. 기본 타입은 값을 비교하고, 참조 타입은 메모리 주소(동일한 객체인지)를 비교 +// 참조 타입 객체의 내용이 같은지를 비교하려면 주로 a.equals(b)를 사용 +// +// 2) 초기화 배열과 맵 +// - new int[2] :size 초기화 +// - new int[]{1,2,3} : 실제 값 초기화 +// - Map test = new HashMap<>(); 맵의 k/v 타입은 앞 변수에 설정한다. val 만사용하다.. +//------------------------------------------------------------------------------------------------------------- + } From f13c67cfccc8f86ea534336e940ffc1496191838 Mon Sep 17 00:00:00 2001 From: renovizee Date: Fri, 25 Jul 2025 21:40:16 +0900 Subject: [PATCH 3/6] feat(leetcode/217): Solve Contains Duplicate (Easy) --- contains-duplicate/renovizee.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/contains-duplicate/renovizee.java b/contains-duplicate/renovizee.java index ce3b62ef2..bef634750 100644 --- a/contains-duplicate/renovizee.java +++ b/contains-duplicate/renovizee.java @@ -1,9 +1,27 @@ +import java.util.HashMap; +import java.util.Map; +// tag renovizee 1week // https://github.com/DaleStudy/leetcode-study/issues/217 // https://leetcode.com/problems/contains-duplicate/ class Solution { public boolean containsDuplicate(int[] nums) { - - return true; + // 시간복잡도 : O(n) + // 공간복잡도 : O(n) + Map countMap = new HashMap<>(); + for (int num : nums) { + int count = countMap.getOrDefault(num, 0); + int addCount = count + 1; + countMap.put(num, addCount); + if (addCount == 2) { + return true; + } + } + return false; } } + +//------------------------------------------------------------------------------------------------------------- +// 기본 문법 피드백 +// 1) Map 기본 문법, ~.getOrDefault() +//------------------------------------------------------------------------------------------------------------- From b8140d5437fa138d138e2fcce1bdc05b525ad77e Mon Sep 17 00:00:00 2001 From: renovizee Date: Fri, 25 Jul 2025 21:49:58 +0900 Subject: [PATCH 4/6] feat(leetcode/128): Solve Longest Consecutive Sequence (Medium) --- longest-consecutive-sequence/renovizee.java | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/longest-consecutive-sequence/renovizee.java b/longest-consecutive-sequence/renovizee.java index a3747e8e6..dffde8989 100644 --- a/longest-consecutive-sequence/renovizee.java +++ b/longest-consecutive-sequence/renovizee.java @@ -1,10 +1,35 @@ +import java.util.HashSet; +import java.util.Set; +// tag renovizee 1week unresolved // https://github.com/DaleStudy/leetcode-study/issues/240 // https://leetcode.com/problems/longest-consecutive-sequence/ class Solution { public int longestConsecutive(int[] nums) { + // 시간복잡도 : O(n) + // 공간복잡도 : O(n) - return 1; + Set numSet = new HashSet<>(); + for (int num : nums) { + numSet.add(num); + } + int maxCount = 0; + for (int num : nums) { + if (numSet.contains(num - 1)) continue; + int currentCount = 1; + while (numSet.contains(num + currentCount)) { + currentCount++; + } + maxCount = Math.max(maxCount, currentCount); + } + return maxCount; } } + + +//------------------------------------------------------------------------------------------------------------- +// 기본 문법 피드백 +// 1) Set numSet = new HashSet<>(); +// 2) Math 활용 Math.max(maxCount, currentCount); +//------------------------------------------------------------------------------------------------------------- From 31290f2dd59fc5e8598005832dbf689be0d8f5de Mon Sep 17 00:00:00 2001 From: renovizee Date: Sat, 26 Jul 2025 09:44:09 +0900 Subject: [PATCH 5/6] feat(leetcode/217): Solve Contains Duplicate (Easy) - feedback map to set --- contains-duplicate/renovizee.java | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/contains-duplicate/renovizee.java b/contains-duplicate/renovizee.java index bef634750..99c5178c0 100644 --- a/contains-duplicate/renovizee.java +++ b/contains-duplicate/renovizee.java @@ -1,24 +1,42 @@ import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; // tag renovizee 1week // https://github.com/DaleStudy/leetcode-study/issues/217 // https://leetcode.com/problems/contains-duplicate/ class Solution { + + // Solv2: hash set (feedback) public boolean containsDuplicate(int[] nums) { // 시간복잡도 : O(n) // 공간복잡도 : O(n) - Map countMap = new HashMap<>(); + Set numsSet = new HashSet<>(); for (int num : nums) { - int count = countMap.getOrDefault(num, 0); - int addCount = count + 1; - countMap.put(num, addCount); - if (addCount == 2) { + if (numsSet.contains(num)) { return true; } + numsSet.add(num); } return false; } + +// Solv1: hash map +// public boolean containsDuplicate(int[] nums) { +// // 시간복잡도 : O(n) +// // 공간복잡도 : O(n) +// Map countMap = new HashMap<>(); +// for (int num : nums) { +// int count = countMap.getOrDefault(num, 0); +// int addCount = count + 1; +// countMap.put(num, addCount); +// if (addCount == 2) { +// return true; +// } +// } +// return false; +// } } //------------------------------------------------------------------------------------------------------------- From d4312fbe40badf1e11292f806bb9f8e3e7d721c7 Mon Sep 17 00:00:00 2001 From: renovizee Date: Sat, 26 Jul 2025 09:47:27 +0900 Subject: [PATCH 6/6] =?UTF-8?q?feat(leetcode/1):=20Solve=20Two=20Sum=20(Ea?= =?UTF-8?q?sy)=20-=20feedback=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- two-sum/renovizee.java | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/two-sum/renovizee.java b/two-sum/renovizee.java index 1b9a628c1..f5fbe10ed 100644 --- a/two-sum/renovizee.java +++ b/two-sum/renovizee.java @@ -11,26 +11,43 @@ // 3. 똑같은 원소를 두번 사용하지 못하고, 정확히 하나의 정답만 있다. class Solution { - // Solv2: map + // Solv3: map 최적화 // 시간복잡도 : O(n) // 공간복잡도 : O(n) public int[] twoSum(int[] nums, int target) { Map map = new HashMap<>(); int[] result = new int[2]; - for (int i = 0; i < nums.length; i++) { - map.put(nums[i], i); - } - for (int i = 0; i < nums.length; i++) { int key = target - nums[i]; if (map.containsKey(key) && map.get(key) != i) { result[0] = i; result[1] = map.get(key); } + map.put(nums[i], i); } return result; - } +//------------------------------------------------------------------------------------------------------------- + // Solv2: map + // 시간복잡도 : O(n) + // 공간복잡도 : O(n) +// public int[] twoSum(int[] nums, int target) { +// Map map = new HashMap<>(); +// int[] result = new int[2]; +// for (int i = 0; i < nums.length; i++) { +// map.put(nums[i], i); +// } +// +// for (int i = 0; i < nums.length; i++) { +// int key = target - nums[i]; +// if (map.containsKey(key) && map.get(key) != i) { +// result[0] = i; +// result[1] = map.get(key); +// } +// } +// return result; +// +// } //------------------------------------------------------------------------------------------------------------- // Solv1: Brute Force // 시간복잡도 : O(n^2)