[sora0349] Week 12 Solutions#1606
Merged
sora0319 merged 5 commits intoDaleStudy:mainfrom Jun 22, 2025
Merged
Conversation
seungriyou
approved these changes
Jun 22, 2025
Contributor
seungriyou
left a comment
There was a problem hiding this comment.
이번 한 주도 고생 많으셨습니다!! 다음 주도 화이팅이에요 🌻
| int end = intervals[i][1]; | ||
| if (prv_end > start) { | ||
| count++; | ||
| prv_end = Math.min(end, prv_end); |
Contributor
There was a problem hiding this comment.
intervals를 start를 기준으로 오름차순 정렬한 후, 그리디하게 항상 Math.min()으로 더 작은 end를 선택하는 방식으로 풀이하신 것 같네요!
intervals를 end를 기준으로 오름차순 정렬하신다면 prv_end가 항상 end 보다 같거나 작을 것이기 때문에 Math.min() 로직을 제거할 수 있을 것 같습니다~!
Contributor
Author
There was a problem hiding this comment.
의견 주셔서 감사합니다
한번 더 생각해 봐야 할 것 같네요
| public class Solution { | ||
| public ListNode removeNthFromEnd(ListNode head, int n) { | ||
| Queue<ListNode> queue = new LinkedList<>(); | ||
| ListNode temp = new ListNode(0, head); |
Contributor
There was a problem hiding this comment.
temp 노드를 이용함으로써 head가 삭제되는 케이스를 커버할 수 있는 좋은 풀이 방법인 것 같아요 🤩
다만, queue를 고정된 크기로 유지하며 O(n)의 공간을 사용하게 되는 부분을 투 포인터를 이용하여 슬라이딩 윈도우로 다룬다면 O(1)의 공간으로 최적화가 가능할 것 같습니다!
Contributor
Author
There was a problem hiding this comment.
공간 복잡도에 대해서는 생각하지 못했는데 투 포인터 방식으로 해볼 수 있겠네요!
| return false; | ||
| } | ||
| stack.push(new TreeNode[]{n1.left, n2.left}); | ||
| stack.push(new TreeNode[]{n1.right, n2.right}); |
Contributor
There was a problem hiding this comment.
스택을 활용하면 이렇게 풀이할 수 있군요!! 저는 재귀로만 풀어보았는데, 참고가 되었습니다 😄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!