105. Construct Binary Tree from Preorder and Inorder Traversal#28
Open
hemispherium wants to merge 1 commit into
Open
105. Construct Binary Tree from Preorder and Inorder Traversal#28hemispherium wants to merge 1 commit into
hemispherium wants to merge 1 commit into
Conversation
nodchip
reviewed
Apr 21, 2026
|
|
||
| TreeNode* build( | ||
| const vector<int>& preorder, | ||
| int preL, |
There was a problem hiding this comment.
lowerCamel と lower_snake が混ざっている点に違和感を感じました。 lower_snake に統一するとよいと思います。
Owner
Author
There was a problem hiding this comment.
そうですね、統一するほうがいいと思います。
| */ | ||
| class Solution { | ||
| public: | ||
| unordered_map<int, int> inorder_val_to_index; |
There was a problem hiding this comment.
こちらのコメントをご参照ください。
5ky7/arai60#22 (comment)
quinn-sasha
reviewed
Apr 21, 2026
Comment on lines
+36
to
+37
| if (it - inorder.begin() != in_right) { | ||
| tree->right = new TreeNode(preorder[pre_left + it - (inorder.begin() + in_left) + 1]); |
There was a problem hiding this comment.
事前にイテレータから添字に変換しておくと、ここら辺のコードが読みやすくなると思います。
条件式やコンストラクタの中で変換すると少し難しくなると思います
Owner
Author
There was a problem hiding this comment.
コメントありがとうございます。そうですね、条件式やコンストラクタの中で変換するのは煩雑になってしまいそうです。
quinn-sasha
reviewed
Apr 21, 2026
| const vector<int>& preorder, | ||
| int preL, | ||
| int preR, | ||
| int inL |
There was a problem hiding this comment.
この preR, inL など添字の役割が少し複雑だと感じました。
preorder は単に左から右にインクリメントする添字があれば十分なのですが、preorder の範囲を管理しているのがやらなくても良いことをやっていることになり複雑になっていると思いました。
範囲を管理するのは inorder にした方が、直感的だと思います。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
この問題:https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/description/
次に解く問題:https://leetcode.com/problems/longest-increasing-subsequence/description/ (Paint Fenceがpremium限定のためスキップ。)