Skip to content

[sora0349] Week 12 Solutions #1606

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

Merged
merged 5 commits into from
Jun 22, 2025
Merged

[sora0349] Week 12 Solutions #1606

merged 5 commits into from
Jun 22, 2025

Conversation

sora0319
Copy link
Contributor

@sora0319 sora0319 commented Jun 21, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

Sorry, something went wrong.

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.

이번 한 주도 고생 많으셨습니다!! 다음 주도 화이팅이에요 🌻

int end = intervals[i][1];
if (prv_end > start) {
count++;
prv_end = Math.min(end, prv_end);
Copy link
Contributor

Choose a reason for hiding this comment

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

intervals를 start를 기준으로 오름차순 정렬한 후, 그리디하게 항상 Math.min()으로 더 작은 end를 선택하는 방식으로 풀이하신 것 같네요!

intervalsend를 기준으로 오름차순 정렬하신다면 prv_end가 항상 end 보다 같거나 작을 것이기 때문에 Math.min() 로직을 제거할 수 있을 것 같습니다~!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

의견 주셔서 감사합니다
한번 더 생각해 봐야 할 것 같네요

public class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
Queue<ListNode> queue = new LinkedList<>();
ListNode temp = new ListNode(0, head);
Copy link
Contributor

Choose a reason for hiding this comment

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

temp 노드를 이용함으로써 head가 삭제되는 케이스를 커버할 수 있는 좋은 풀이 방법인 것 같아요 🤩

다만, queue를 고정된 크기로 유지하며 O(n)의 공간을 사용하게 되는 부분을 투 포인터를 이용하여 슬라이딩 윈도우로 다룬다면 O(1)의 공간으로 최적화가 가능할 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

공간 복잡도에 대해서는 생각하지 못했는데 투 포인터 방식으로 해볼 수 있겠네요!

return false;
}
stack.push(new TreeNode[]{n1.left, n2.left});
stack.push(new TreeNode[]{n1.right, n2.right});
Copy link
Contributor

Choose a reason for hiding this comment

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

스택을 활용하면 이렇게 풀이할 수 있군요!! 저는 재귀로만 풀어보았는데, 참고가 되었습니다 😄

@sora0319 sora0319 merged commit dbbe77f into DaleStudy:main Jun 22, 2025
3 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 4기 Jun 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

None yet

2 participants