Skip to content

[uraflower] Week11 Solutions #1570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

uraflower
Copy link
Contributor

@uraflower uraflower commented Jun 9, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

@uraflower uraflower moved this from Solving to In Review in 리트코드 스터디 4기 Jun 13, 2025
Copy link
Contributor

@seungriyou seungriyou left a comment

Choose a reason for hiding this comment

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

복잡도 계산이나 풀이 설명을 깔끔하게 작성해주셔서 공부가 많이 되었습니다!

이번 한 주도 고생 많으셨어요~! 🍀

const queue = [[-1, 0]]; // 부모 노드, 자식 노드
const visited = new Set();

while (queue.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

무방향 그래프가 트리의 조건인 connected && acyclic 을 만족하는지 확인하는 방법으로, BFS나 DFS 외에도 union-find도 있다고 해요!

저는 그래프나 트리 문제를 풀 때마다 너무 당연하게 BFS/DFS로만 푸는 경향이 있었는데, 이번 문제를 통해 union-find로도 풀어보게 되었어서 함께 공유드려요~!

nodes[n].next = null; // 여기서 모든 노드의 next를 null로 변경
// 이렇게 안 하면 next 바꾸기 한 다음에 맨 마지막 노드의 next만 null로 바꿔야 함
n++
}
Copy link
Contributor

Choose a reason for hiding this comment

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

추가적인 해시맵을 생성해 연결 리스트의 각 노드를 O(1)으로 조회할 수 있게 함으로써 가독성 좋게 쓰인 풀이인 것 같습니다!

다만, 속도가 다른 투 포인터를 이용하여 연결 리스트를 절반으로 나누고 오른쪽 리스트를 뒤집은 후, 두 리스트를 첫 노드부터 번갈아가며 다시 엮어나가는 방식으로 푼다면 추가 공간을 사용하지 않고 공간 복잡도를 O(1)으로 최적화 할 수 있을 것 같아요!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

2 participants