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
15 changes: 15 additions & 0 deletions contains-duplicate/xeulbn.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)

피드백: 집합에 원소를 하나씩 넣으며 이미 존재하는지 검사하는 방식으로, 시간 복잡도는 원소 개수만큼의 반복으로 O(n)이다. 공간은 최악의 경우 모든 원소를 저장하므로 O(n).

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

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

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

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

for(int num : nums){
if(numberCheck.contains(num)){
return true;
}
numberCheck.add(num);
}
return false;
}
}
21 changes: 21 additions & 0 deletions house-robber/xeulbn.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
  • 설명: 이 코드는 이전 계산 결과를 저장하며 최적의 선택을 하는 DP(동적 프로그래밍) 패턴을 사용하여 최대 금액을 계산합니다.

📊 시간/공간 복잡도 분석

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

피드백: 한 번의 반복으로 각 위치별 최적값을 계산하며, 배열 크기만큼 반복한다. 공간은 DP 배열 크기와 같다.

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

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

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.

dp로 구현해주셨네요. 코드 조금 수정하면 공간 복잡도를 더 줄일 수 있을 것 같아요!👍

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

class Solution {

public int rob(int[] nums) {
if (nums.length == 1) {
return nums[0];
}

int[] dp = new int[nums.length];

dp[0] = nums[0];
dp[1] = Math.max(nums[0], nums[1]);

for (int i = 2; i < nums.length; i++) {
dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i]);
}

return dp[nums.length - 1];
}
}
29 changes: 29 additions & 0 deletions longest-consecutive-sequence/xeulbn.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, Union Find
  • 설명: 이 코드는 HashSet을 이용해 연속된 수를 찾고, 연속 구간의 길이를 계산하는 방식으로, 해시 자료구조 활용과 연속 구간 병합을 통해 최장 연속 수를 찾는 패턴입니다.

📊 시간/공간 복잡도 분석

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

피드백: 집합에 원소를 넣고, 각 원소에 대해 연속된 수를 확장하는 방식으로, 모든 원소를 최대 한 번씩만 검사한다.

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

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

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.

hashSet 사용해서 효율적으로 잘 구현해주셨네요. 코드에 시간/공간 복잡도도 적어주시면 좋을 것 같습니다!

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

class Solution {
public int longestConsecutive(int[] nums) {
Set<Integer> set = new HashSet<>();

for (int num : nums) {
set.add(num);
}

int maxLength = 0;

for (int num : set) {
if (!set.contains(num - 1)) {
int currentNum = num;
int currentLength = 1;

while (set.contains(currentNum + 1)) {
currentNum++;
currentLength++;
}

maxLength = Math.max(maxLength, currentLength);
}
}

return maxLength;
}
}
31 changes: 31 additions & 0 deletions top-k-frequent-elements/xeulbn.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
  • 설명: 이 코드는 각 숫자의 빈도수를 Hash Map으로 저장하고, 우선순위 큐를 이용해 상위 k개를 찾는 방식으로 구성되어 있습니다. Hash Map은 빈도수 계산에, Priority Queue는 정렬 및 선택에 사용됩니다.

📊 시간/공간 복잡도 분석

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

피드백: 모든 원소를 세고, 우선순위 큐를 통해 k개를 유지하는 방식으로, 시간 복잡도는 O(n log k)이다. 공간은 맵과 큐를 합쳐 O(n).

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

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

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.

우선순위 큐 사용해서 풀이해주셨네요. 파이썬 사용하는데 자바 문법도 확인할 수 있어서 좋았습니다👍

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

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

for(int i=0;i<nums.length;i++){
countMap.put(nums[i],countMap.getOrDefault(nums[i],0)+1);
}
PriorityQueue<Integer> pq = new PriorityQueue<>(
(a,b)-> countMap.get(a) - countMap.get(b)
);

for(int num: countMap.keySet()){
pq.offer(num);

if(pq.size()>k){
pq.poll();
}
}

int[] answer = new int[k];

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

return answer;

}
}
17 changes: 17 additions & 0 deletions two-sum/xeulbn.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
  • 설명: 이 코드는 해시맵을 이용해 각 숫자의 인덱스를 저장하고, 필요한 값이 존재하는지 빠르게 조회하여 두 수의 합이 target이 되는 경우를 찾는다.

📊 시간/공간 복잡도 분석

복잡도
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> numIndexMap = new HashMap<>();

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

return new int[]{};
}
}
Loading