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
30 changes: 30 additions & 0 deletions non-overlapping-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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy
  • 설명: 이 코드는 겹치지 않는 구간을 찾기 위해 끝나는 시간 기준 정렬 후 선택하는 그리디 전략을 사용합니다. 최소 제거 개수를 구하는 문제에 적합한 패턴입니다.

📊 시간/공간 복잡도 분석

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

피드백: 배열 정렬 후 한 번 순회하며 겹침 여부를 체크하는 방식으로, 정렬이 시간 복잡도에 가장 큰 영향을 미친다. 정렬 후 순회는 O(n).

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution {
public int eraseOverlapIntervals(int[][] intervals) {
/**
1.prob: 겹치지 않는 최소한의 non-oerlapping interval 제거
2.constraints
- inverval.lenght min=1, max = 100,000
3.solutions - Greedy
- end 기준 오름차순 정렬
- 이전 interval end 저장
- 다음 interval check, 안겹치면 -> 선택, 겹치면 count++
Time: O(n logn), Space: O(1)
*/
int count = 0;

//end 기준 ascending 정렬
Arrays.sort(intervals, (a, b) -> a[1] - b[1]);
int end = intervals[0][1];

//겹치면 count++, 안겹치면 end update
for(int i = 1; i < intervals.length; i++) {
if(intervals[i][0] < end) {
count++;
} else {
end = intervals[i][1];
}
}

return count;
}
}
46 changes: 46 additions & 0 deletions remove-nth-node-from-end-of-list/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers
  • 설명: 이 코드는 fast와 slow 두 포인터를 이용하여 리스트의 뒤에서 n번째 노드를 찾고 제거하는 방식으로, 두 포인터 패턴에 속합니다.

📊 시간/공간 복잡도 분석

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

피드백: 빠른 포인터를 n칸 이동시킨 후, 느린 포인터와 함께 끝까지 이동하며 제거 대상 노드 위치를 찾는다. 한 번의 순회로 해결 가능하다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
/**
1.linked list 에서 뒤에서 n번째 node remove
2.constraints:
node 개수(sz) min=1, max=30
n값 min = 1, max= sz
3.solutions: two pointers
- fast, slow pointer 2개의 간격 = n
- fast 가 끝지점에 도달하면 그때 slow.next 를 제거
time: O(n), space: O(1)
*/

ListNode dummy = new ListNode(0);
dummy.next = head;

ListNode fast = dummy;
ListNode slow = dummy;

//fast pointer n+1칸 이동, fast - slow = n
for(int i = 0; i <= n; i++) {
fast = fast.next;
}

while(fast != null) {
fast = fast.next;
slow = slow.next;
}

//slow pointer 의 다음 노드(slow.next) 제거
slow.next = slow.next.next;

return dummy.next;

}
}
44 changes: 44 additions & 0 deletions same-tree/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: DFS
  • 설명: 이 코드는 재귀를 이용한 깊이 우선 탐색(DFS) 방식으로 두 트리의 구조와 값을 비교하여 동일한지 판단합니다.

📊 시간/공간 복잡도 분석

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

피드백: 트리의 모든 노드를 한 번씩 방문하는 재귀 방식으로, 트리의 높이만큼 호출 스택이 쌓인다. 구조와 값 비교를 동시에 수행한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public boolean isSameTree(TreeNode p, TreeNode q) {
/**
1.problem: 2개의 bst 가 동일한지 체크
2.constraints - 구조와 노드가 동일해야된다
3.solution - DFS
1) 두 트리의 노드가 모두 null -> true
2) 둘중 하나만 null -> false
3) 값이 다르면 false
4)재귀로 트리의 구조가 동일한지 체크
*/

if(p == null && q == null) {
return true;
}
if(p == null || q == null) {
return false;
}
if(p.val != q.val) {
return false;
}

if(isSameTree(p.left, q.left) && isSameTree(p.right, q.right)) {
return true;
}
return false;
}

}
Loading