- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 226
[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
Conversation
There was a problem hiding this 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); |
There was a problem hiding this comment.
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를 선택하는 방식으로 풀이하신 것 같네요!
intervals
를 end를 기준으로 오름차순 정렬하신다면 prv_end
가 항상 end
보다 같거나 작을 것이기 때문에 Math.min()
로직을 제거할 수 있을 것 같습니다~!
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)의 공간으로 최적화가 가능할 것 같습니다!
There was a problem hiding this comment.
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}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스택을 활용하면 이렇게 풀이할 수 있군요!! 저는 재귀로만 풀어보았는데, 참고가 되었습니다 😄
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!