Skip to content

Create 103. Binary Tree Zigzag Level Order Traversal.md#10

Merged
Mike0121 merged 2 commits intomainfrom
103.-Binary-Tree-Zigzag-Level-Order-Traversal
Nov 1, 2025
Merged

Create 103. Binary Tree Zigzag Level Order Traversal.md#10
Mike0121 merged 2 commits intomainfrom
103.-Binary-Tree-Zigzag-Level-Order-Traversal

Conversation

@Mike0121
Copy link
Copy Markdown
Owner

@Mike0121 Mike0121 commented May 5, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

なんか必要以上に複雑なことをしている感想を持ちました。queueへの要素の追加、取り出しをlevelの偶奇数に応じて使い分けていて、読むのも結構大変でした。next_level_nodesへの要素の追加、取り出しの処理は共通にして、level_nodes_valuesへの追加のタイミングでappendappendleftを使い分ける方がシンプルかなと思います。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ご返信遅くなってしまいすみません。(自分の頭の中がパズル化していたので)他の方がどのように考えたのか気になったので、非常に参考になりました。自分の頭でも整理し直して、より簡潔に書き直すことができたと思います。

1. ahayashiさんのアドバイスを基に書き直し
2. 補助関数を用いたDFSの追加
Copy link
Copy Markdown

@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.

4thのコードについてコメントしました。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

関数名はcamelCaseかsnake_caseのどちらかにして欲しいです。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます、混じってますね。気をつけます。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

これで良いですね。わざわざtupleにする必要はないと思います。

Suggested change
next_level_nodes = deque([(root)])
next_level_nodes = deque([root])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ListのListではなくてdeque objectのListが返っていますね。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

list(zigzag_ordered_level_nodes)が適切ですかね。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[ list(node) for node in zigzag_ordered_level_nodes] こうですかね。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。

@Mike0121 Mike0121 changed the title 103. Binary Tree Zigzag Level Order Traversal Create 103. Binary Tree Zigzag Level Order Traversal.md Nov 1, 2025
@Mike0121 Mike0121 merged commit 61b3c57 into main Nov 1, 2025
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.

2 participants