-
-
Notifications
You must be signed in to change notification settings - Fork 195
[강희찬] WEEK 2 Solution #356
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
HC-kang
commented
Aug 22, 2024
•
edited
Loading
edited
- Valid Anagram
- Counting Bits
- Encode and Decode Strings
- Construct Binary Tree From Preorder And Inorder Traversal
- Decode Ways
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.
수고 많으셨습니다! 잘 푸신 것 같아요!
} | ||
|
||
// T.C: O(N) | ||
// S.C: O(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.
혹시 공간 복잡도 분석하실 때 문자열 슬라이싱에 들어가는 메모리를 고려하셨을까요?
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.
@DaleSeo 엇 중요한 부분 짚어주셔서 감사합니다 달레님!
슬라이스될 때 마다 복제되는 길이가 대략 절반�씩 줄어 들거라고 생각했는데, 최악의 경우에는 n번의 순회동안 n-1, n-2...1씩 복사를 하겠네요
그렇다면 O(n^2)가 맞을 것 같습니다!
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.
고생하셨습니다!
if (preorder.length === 0 || inorder.length === 0) { | ||
return null; | ||
} | ||
const root = new TreeNode(preorder[0]); | ||
const idx = inorder.indexOf(preorder[0]); | ||
root.left = buildTree(preorder.slice(1, idx + 1), inorder.slice(0, idx)); | ||
root.right = buildTree(preorder.slice(idx + 1), inorder.slice(idx + 1)); | ||
|
||
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.
가독성이 엄청 좋네요!! 도움이 많이 됐습니다.
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.
좋게 봐 주셔서 감사합니다!