Skip to content

Conversation

mike2ox
Copy link
Contributor

@mike2ox mike2ox commented Feb 16, 2025

답안 제출 문제

체크 리스트

  • 우측 메뉴에서 PR을 Projects에 추가해주세요.
  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@mike2ox mike2ox self-assigned this Feb 16, 2025
@mike2ox mike2ox requested a review from a team as a code owner February 16, 2025 08:24
@github-actions github-actions bot added the ts label Feb 16, 2025
@mike2ox mike2ox requested a review from KwonNayeon February 16, 2025 08:24
@mike2ox
Copy link
Contributor Author

mike2ox commented Feb 21, 2025

#287 은 어떻게 풀어야할지 생각이 안나서 다음주 문제풀 때 해결해보겠습니다.

Comment on lines +1 to +6
/**
* Source: https://www.lintcode.com/problem/178/
* Solution: 유효한 트리인지 순회하면서 확인하면 되기에 BFS로 구현
* 시간 복잡도: O(V + E) - 노드와 간선에 한번은 방문
* 공간 복잡도: O(V + E) - 인접리스트 만큼의 공간 필요
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

주석을 자세히 적어주셔서, 익숙하지 않은 언어인데도 알고리즘을 이해하기 수월했습니다!

Comment on lines +26 to +55
function reorderList(head: ListNode | null): void {
if (!head || !head.next) return;

// 1. 모든 노드를 배열에 저장
const nodes: ListNode[] = [];
let current: ListNode | null = head;
while (current) {
nodes.push(current);
current = current.next;
}

// 2. 배열의 양끝에서 시작하여 리스트 재구성
let left = 0;
let right = nodes.length - 1;

while (left < right) {
// 현재 왼쪽 노드의 다음을 저장
nodes[left].next = nodes[right];
left++;

if (left === right) break;

// 현재 오른쪽 노드를 다음 왼쪽 노드에 연결
nodes[right].next = nodes[left];
right--;
}

// 마지막 노드의 next를 null로 설정
nodes[left].next = null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

공간복잡도 개선을 위해 slow/fast 포인터를 사용한 방법도 도전해보시면 좋을 것 같습니다!

Copy link
Contributor

Choose a reason for hiding this comment

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

@mike2ox 님 이번 주도 고생하셨습니다! 주석을 꼼꼼하게 적어주셔서 코드 리뷰가 수월했고, 공부도 많이 되었습니다. 덕분에 "Maximum depth of binary tree"를 반복문으로 접근해볼 수 있었습니다 😄

@mike2ox mike2ox merged commit cd7eaed into DaleStudy:main Feb 22, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

3 participants