-
-
Notifications
You must be signed in to change notification settings - Fork 195
[박종훈] 7주차 답안 제출 #126
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
[박종훈] 7주차 답안 제출 #126
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.
보고 배우겠습니다. 🙇
저에게는 아직 어려운 풀이법이네요 하하
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.
포인터 방식은 저도 어려워서
한참 잡고있었네요 ㅎㅎ
공간 복잡도가 줄긴 하는데
직관적이지는 못하다고 생각됩니다 ㅎㅎ
(데이터가 엄청 많지 않은 이상 크게 차이도 없고, 오히려 손해일수도...)
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.
우선 선형적으로 길이를 구한 뒤 다시 처음부터 시작하여 length - n - 1 까지를 구해 타겟팅된 노드를 제거하는 전략이군요. 제가 생각지 못한 풀이법이라 새롭네요 ㅎㅎ
// left로 갈 때 max를 자신으로, right로 갈 때는 min을 자신으로 | ||
if (!(dfs(node.left, min, node.val) | ||
&& dfs(node.right, node.val, max))) { | ||
return false; | ||
} |
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.
TreeNode
끼리 비교하지 않고 Int 값으로 비교한 게 인상적이네요 ✨
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.
포인터 없이 이렇게 풀어도 되는군요.. 저도 포인터는 쓸때마다 직관적으로 그려지지가 않는데 너무 흔하게 쓰이는 테크닉이라 버릴수도 없고 고민입니다 참고하도록 하겠습니다!
list.add(current); | ||
current = current.next; | ||
} | ||
list.add(current); |
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.
혹시 이 부분을 빼고 위에 while 조건을 current != null 만 하는 방법은 어떨까요?
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.
while (current != null) {
list.add(current);
current = current.next;
}
말씀해주신대로 이렇게 수정해도 잘 동작하네요...! : ) 좋을 것 같습니다...!
Reorder List
문제: https://leetcode.com/problems/reorder-list/
풀이: https://algorithm.jonghoonpark.com/2024/06/10/leetcode-143
Remove Nth Node From End of List
문제: https://leetcode.com/problems/remove-nth-node-from-end-of-list/
풀이: https://algorithm.jonghoonpark.com/2024/06/10/leetcode-19
Lowest Common Ancestor of a Binary Search Tree
문제: https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/
풀이: https://algorithm.jonghoonpark.com/2024/06/10/leetcode-235
Binary Tree Level Order Traversal
문제: https://leetcode.com/problems/binary-tree-level-order-traversal/
풀이: https://algorithm.jonghoonpark.com/2024/06/10/leetcode-102
Validate Binary Search Tree
문제: https://leetcode.com/problems/validate-binary-search-tree/
풀이: https://algorithm.jonghoonpark.com/2024/06/10/leetcode-98