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
40 changes: 40 additions & 0 deletions merge-intervals/hyeri0903.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Sorting, Interval Merging
  • 설명: 이 코드는 먼저 배열을 정렬한 후, 겹치는 구간을 병합하는 방식으로 문제를 해결합니다. 정렬과 병합 과정을 통해 효율적으로 겹치는 구간을 처리하는 패턴입니다.

📊 시간/공간 복잡도 분석

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

피드백: 배열 정렬에 O(n log n) 시간이 소요되고, 병합 결과를 저장하는 리스트는 최대 O(n) 크기입니다. 정렬 후 한 번 순회하며 병합하므로 전체 시간 복잡도는 O(n log n)입니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class Solution {
public int[][] merge(int[][] intervals) {
/**
1.prob: overlapping 되는 곳을 merge 해서 return
2.constraints
- len(intervalse) min = 1, max= 10000
- start, end value min = 0, max = 10000
3.solution
- sorting array -> merge overlapping values
time: O(n log n)
*/

int n = intervals.length;
Arrays.sort(intervals, (a,b) -> Integer.compare(a[0], b[0]));

List<int[]> answer = new ArrayList<>();
int start = intervals[0][0];
int end = intervals[0][1];

for(int i = 1; i < n; i++) {
int nextStart = intervals[i][0];
int nextEnd = intervals[i][1];

//overlap
if(end >= nextStart) {
end = Math.max(end, nextEnd);
} else {
answer.add(new int[]{start, end});

start = nextStart;
end = nextEnd;

}
}

//last intervals
answer.add(new int[]{start, end});
return answer.toArray(new int[answer.size()][]);
}
}
30 changes: 30 additions & 0 deletions missing-number/hyeri0903.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Sorting
  • 설명: 이 코드는 배열을 정렬한 후 누락된 숫자를 찾기 위해 순차적으로 비교하는 방식으로, 정렬 알고리즘이 핵심 패턴입니다.

📊 시간/공간 복잡도 분석

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

피드백: 배열 정렬에 O(n log n) 시간이 소요되고, 이후 한 번 순회하며 누락된 숫자를 찾습니다. 정렬 후 비교하는 방식이므로 전체 시간 복잡도는 O(n log n)입니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution {
public int missingNumber(int[] nums) {
/**
1.distinc number 로 이루어진 0~n 까지의 배열 중 missing number return
2.constraints
- n 최소 = 1, 최대 = 10000
- 배열길이 min=0, max=n
3.solutions
- sorting 하고 for문으로 missing num check. time: O(n log n), space: O(1)
- 전체 sum - 실제 sum
*/

Arrays.sort(nums);
int n = nums.length;
int answer = 0;
int i = 0;

for(i = 0; i < n; i++) {
if(nums[i] != i) {
answer = i;
return answer;
}
}
if(i == n) {
answer = n;
return answer;
}
return answer;
}
}
Loading