Skip to content

Conversation

shining-ai
Copy link
Owner


current_preorder_index = 0

def array_to_tree(inorder_left, inorder_right):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

区間は [inorder_left, inorder_right) の開閉区間で持たせたほうが一般的だと思います。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

自分の分かりやすい方を主観で決めて実装していました。
開閉区間で統一するようにします。

) -> Optional[TreeNode]:
current_preorder_index = 0

def array_to_tree(splied_inorder):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

splied という単語が辞書で見つかりませんでした。綴りをご確認いただいてもよろしいでしょうか?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

splitのtypoでした。

Copy link

@hayashi-ay hayashi-ay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

良いと思います。別途preorder_indexを管理しない方法でも書いてみても良いかなと思います。

nonlocal current_preorder_index
if inorder_left >= inorder_right:
return None
val = preorder[current_preorder_index]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valだけだとこれは何の値を意味するのかがわからないかなと思います。どこまで変数名として表現するかは難しいですが、valだけでは、[inorder_left, inorder_right)の区間で表されるTreeのrootの値ということを読み取るのは難しいと思います。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants