Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions contains-duplicate/hyunpill3.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set
  • 설명: 배열에서 중복 여부를 확인하기 위해 해시 집합(HashSet)을 이용해 한 번씩 검사하는 패턴입니다. 시간 복잡도는 O(n), 추가 공간은 O(n)입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 한 번의 순회와 해시셋 저장으로 중복 여부를 결정합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
public boolean containsDuplicate(int[] nums) {
HashSet<Integer> set = new HashSet<>();
for (int num : nums) {
if (set.contains(num)) {
return true;
}
set.add(num);
}
return false;
}
}
15 changes: 15 additions & 0 deletions house-robber/hyunpill3.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Two Pointers
  • 설명: 배열의 연속된 원소를 점진적으로 최적해로 구성하는 DP 패턴이며, 공간을 줄인 상태로 이전 두 값을 이용해 최댓값을 갱신하는 형태로 Two Pointers의 변형으로 볼 수 있습니다. 각 위치의 최댓값은 현재 값과 이전의 최댓값 조합으로 계산되며, 연속된 선택을 피하는 문제에 해당합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(1)

피드백: 상태를 두 변수로 유지하며 선형 시간에 해결합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public int rob(int[] nums) {
int next = 0;
int next2 = 0;
Comment on lines +3 to +4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공간복잡도를 O(1) 로 풀어내신 점이 인상적이네요! 👍


for (int num : nums) {
int current = Math.max(next, next2 + num);

next2 = next;
next = current;
}

return next;
}
}
26 changes: 26 additions & 0 deletions longest-consecutive-sequence/hyunpill3.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Greedy, Two Pointers
  • 설명: 집합으로 중복 제거 후 각 수의 시작점 여부를 확인하고 연속 부분 수열의 길이를 확장하는 방식으로 최장 연속 부분 수열 길이를 구하므로 해시 세트와 탐색으로 시작점 기반의 탐욕적 확장을 사용합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 각 원소를 한 번씩 검사하고, 시작점 여부를 확인하여 전체를 탐색합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public int longestConsecutive(int[] nums) {
Set<Integer> 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;
}
}
17 changes: 17 additions & 0 deletions top-k-frequent-elements/hyunpill3.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Sorting
  • 설명: 코드에서 각 값의 빈도수를 세기 위해 GroupingBy를 사용하며, 결과를 빈도수로 내림차순 정렬한 뒤 상위 k개를 선택합니다. 해시 맵 기반 집계와 정렬을 이용한 선택 패턴이 핵심입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n log n)
Space O(n)

피드백: 스트림 기반 복잡도는 정렬에 의해 결정되며 구현은 간결합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public int[] topKFrequent(int[] nums, int k) {
List<Integer> 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();
}
}
12 changes: 12 additions & 0 deletions two-sum/hyunpill3.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Two Pointers
  • 설명: 해시맵을 이용한 탐색으로 보완 값이 이전에 등장했는지 빠르게 확인하는 방식으로 문제를 풀이합니다. 현재 인덱스와 목표값의 차를 키로 저장하고, 필요 값이 이미 존재하면 해를 반환합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 한 번의 순회로 해결하며 최적의 보조 공간을 사용합니다.

개선 제안: 마지막에 누락된 return 문이 필요해 보완 권장: 모든 경우를 커버하도록 종료 시 반환값을 추가.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
public int[] twoSum(int[] nums, int target) {
HashMap<Integer, Integer> 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)
}
}
}
Loading