Create 103. Binary Tree Zigzag Level Order Traversal.md#10
Conversation
There was a problem hiding this comment.
なんか必要以上に複雑なことをしている感想を持ちました。queueへの要素の追加、取り出しをlevelの偶奇数に応じて使い分けていて、読むのも結構大変でした。next_level_nodesへの要素の追加、取り出しの処理は共通にして、level_nodes_valuesへの追加のタイミングでappendとappendleftを使い分ける方がシンプルかなと思います。
There was a problem hiding this comment.
ご返信遅くなってしまいすみません。(自分の頭の中がパズル化していたので)他の方がどのように考えたのか気になったので、非常に参考になりました。自分の頭でも整理し直して、より簡潔に書き直すことができたと思います。
1. ahayashiさんのアドバイスを基に書き直し 2. 補助関数を用いたDFSの追加
There was a problem hiding this comment.
関数名はcamelCaseかsnake_caseのどちらかにして欲しいです。
There was a problem hiding this comment.
ありがとうございます、混じってますね。気をつけます。
There was a problem hiding this comment.
これで良いですね。わざわざtupleにする必要はないと思います。
| next_level_nodes = deque([(root)]) | |
| next_level_nodes = deque([root]) |
There was a problem hiding this comment.
ListのListではなくてdeque objectのListが返っていますね。
There was a problem hiding this comment.
list(zigzag_ordered_level_nodes)が適切ですかね。
There was a problem hiding this comment.
[ list(node) for node in zigzag_ordered_level_nodes] こうですかね。
https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/description/?envType=list&envId=rbx9vwti