solved binary_tree_level_order_traversal#42
Open
SuperHotDogCat wants to merge 1 commit intoarai60from
Open
Conversation
oda
reviewed
Feb 15, 2025
Comment on lines
+21
to
+22
| if len(node_ids) > 0: | ||
| level_to_nodes.append(node_ids) |
There was a problem hiding this comment.
単に if node_ids: でもいいでしょう。
個人的には current_level_nodes = next_level_nodes の前に置きたいです。
current_level_nodes に None が入っているので、これいるんですね。よしあしですが、入るかもしれない前提で書いたほうが単純かもしれません。
| current_level_nodes = [root] | ||
| while current_level_nodes: | ||
| next_level_nodes = [] | ||
| node_ids = [] |
There was a problem hiding this comment.
問題文の単語に合わせて、node_vals としてもよいように感じました。他の単語に合わせて current_level_vals とかでもよいかもしれません。
| # self.right = right | ||
| class Solution: | ||
| def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: | ||
| level_to_nodes = [] |
There was a problem hiding this comment.
こちら、階層ごとの値が入っているというよりは、階層とそれに紐づく node が入っているように見えました。level_order_vals や all_level_vals が浮かびました。
TORUS0818
reviewed
Feb 24, 2025
| class Solution: | ||
| def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: | ||
| level_traversed_node_ids = [] | ||
| def append_by_depth(node: Optional[TreeNode], depth: int): |
There was a problem hiding this comment.
自分ならids -> vals、depth -> levelを使うと思います。
表現にバリエーションが出てしまうと、後々混乱の原因になるかもと思いました。
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/binary-tree-level-order-traversal/description/?envType=problem-list-v2&envId=xo2bgr0r