-
Notifications
You must be signed in to change notification settings - Fork 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
[moonhyeok] Week10 #1015
[moonhyeok] Week10 #1015
Conversation
* Source: https://leetcode.com/problems/invert-binary-tree/ | ||
* 풀이방법: 재귀를 이용하여 트리를 뒤집음 | ||
* | ||
* 시간복잡도: O(n) - n은 트리의 노드 수 |
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를 새로 만들어서 return하는데 in-place로 구현할 수도 있을것같아요
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-place로 바로 결과를 보낼 수 있는걸 잊었네요 ㅎㅎ
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.
@mike2ox 님, 이번주도 고생 많으셨습니다~
벌써 2/3을 마치셨네요! 이제 남은 5주도 지금까지 하신만큼 꼭! 더 많은 것을 얻어가실 수 있으시면 좋겠습니다!
@@ -0,0 +1,21 @@ | |||
/** | |||
* Source: https://leetcode.com/problems/jump-game/ | |||
* 풀이방법: 그리디로 접근 |
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.
DFS로 그냥 해봤는데 시간오버떠서 뭔가 이미 도착했다는 전제하에 역으로 출발점을 찾는 식으로 하니까 해결됐습니다 ㅎㅎ..
PS할 때마다 이건 어떤 풀이법이 좋은지 찾는게 참 헷갈리네요
let head = null; | ||
let tail = null; | ||
|
||
for (let i = 0; i < sorted.length; i++) { |
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.
처음에 변수 선언과 동시에 초기화를 해줬었는데 순회 내부 로직이 안떠올라서 더 고민안하고 내버렸는데 리팩토링 한번 해보겠습니다 :)
let left = 0; | ||
let right = nums.length - 1; | ||
|
||
while (left <= 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.
중요하지 않은 내용입니다!
while
문 내부의 코드가 흐름상 분명 불필요한 사족 없이 잘 짜여진 코드인데,
개인적으로 저는 묘하게 답답하고 읽기 힘든 느낌이 들어요.
분기문을 한줄로 간단하게 쓰신것도 좋지만, 약간의 구분감을 주시는것도 읽는 사람들에게 도움이 되지 않을까 싶어요!
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.
너무 간단해서 중괄호를 제거했는데 그게 오히려 독이 됐군요. 가독성 부분을 더 신경써보겠습니다 :)
감사합니다! 리뷰하신 부분 고려해서 PS풀 때 신경쓰겠습니다 :) |
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.