-
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
[ganu] Week 10 #1008
[ganu] Week 10 #1008
Conversation
/** | ||
* @param {TreeNode} root | ||
* @return {TreeNode} | ||
*/ | ||
var invertTree = function (root) { | ||
const dfs = (current) => { | ||
if (!current) { | ||
return; | ||
} | ||
|
||
const temp = current.left; | ||
current.left = current.right; | ||
current.right = temp; | ||
|
||
dfs(current.left); | ||
dfs(current.right); | ||
}; | ||
|
||
dfs(root); | ||
|
||
return root; | ||
}; |
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와 재귀를 활용하면 더 깔끔한 코드로 구현할 수 있겠어요. 참고가 되었습니다. 감사합니다!
// Time complexity: O(n) | ||
// Space complexity: 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.
저도 거의 동일한 방식으로 풀었습니다! 표현하는 방식 등 여러가지로 파이썬과 다른 부분이 있어서 비교해서 보는 재미가 있었어요. 시간/공간 복잡도에 대한 설명을 추가해주시면 더 좋을 것 같습니다. 이번 주도 고생하셨습니다!
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.