Skip to content
Open
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
16 changes: 16 additions & 0 deletions contains-duplicate/jaekwang97.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을 사용하여 각 요소의 존재 여부를 빠르게 확인하는 방식으로 구현되어 있습니다. 따라서 해시 맵 또는 해시 셋 패턴에 속합니다.

📊 시간/공간 복잡도 분석

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

피드백: 집합에 모든 원소를 하나씩 넣으며 중복 여부를 검사하므로 시간 복잡도는 배열 크기만큼 선형입니다. 추가로 집합이 저장하는 원소 수만큼 공간이 필요합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.*;

class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> seen = new HashSet<>();

for (int num : nums) {
if (seen.contains(num)) {
return true;
}
seen.add(num);
}

return false;
}
}
38 changes: 38 additions & 0 deletions top-k-frequent-elements/jaekwang97.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, Heap / Priority Queue
  • 설명: 이 코드는 각 숫자의 빈도수를 HashMap으로 계산하고, 우선순위 큐를 이용해 빈도 높은 요소를 추출하는 방식으로 동작합니다. 따라서 Hash Map과 Heap 패턴이 사용됩니다.

📊 시간/공간 복잡도 분석

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

피드백: 모든 원소의 빈도를 계산하는 데 O(n), 이후 우선순위 큐에 넣고 k개를 뽑는 과정이 각각 O(n log n)입니다. 공간은 빈도수 저장과 큐에 저장하는 데 필요합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.util.*;

class Solution {
static class Item implements Comparable<Item> {
int num;
int count;

Item(int num, int count) {
this.num = num;
this.count = count;
}

@Override
public int compareTo(Item other) {
return Integer.compare(other.count, this.count);
}
}

public int[] topKFrequent(int[] nums, int k) {
Map<Integer, Integer> counts = new HashMap<>();

for (int num : nums) {
counts.put(num, counts.getOrDefault(num, 0) + 1);
}

PriorityQueue<Item> queue = new PriorityQueue<>();
for (Map.Entry<Integer, Integer> entry : counts.entrySet()) {
queue.add(new Item(entry.getKey(), entry.getValue()));
}

int[] answer = new int[k];
for (int i = 0; i < k; i++) {
answer[i] = queue.poll().num;
}

return answer;
}
}
17 changes: 17 additions & 0 deletions two-sum/jaekwang97.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
  • 설명: 이 코드는 해시맵을 이용하여 각 숫자의 인덱스를 저장하고, 목표값과의 차이를 빠르게 찾는 방식으로 해결합니다. 효율적인 검색을 위해 해시맵이 사용된 것이 특징입니다.

📊 시간/공간 복잡도 분석

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

피드백: 한 번의 배열 순회와 해시맵 검색으로 해결하며, 해시맵이 원소 수만큼 공간을 차지합니다. 시간은 배열 크기만큼 선형입니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.*;

class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> seen = new HashMap<>();

for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (seen.containsKey(complement)) {
return new int[] { seen.get(complement), i };
}
seen.put(nums[i], i);
}

return new int[] {};
}
}
Loading