Skip to content

103. Binary Tree Zigzag Level Order Traversal#41

Open
skypenguins wants to merge 1 commit into
mainfrom
leetcode/arai60/problem-103
Open

103. Binary Tree Zigzag Level Order Traversal#41
skypenguins wants to merge 1 commit into
mainfrom
leetcode/arai60/problem-103

Conversation

@skypenguins

Copy link
Copy Markdown
Owner

@skypenguins skypenguins self-assigned this Jun 28, 2026
Comment thread memo.md
if node.right:
pending_nodes.append(node.right)

if len(zigzag_level) % 2 != 0:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

while 文が終わったあとに、奇数行だけ反転させるという方法もあります。

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.

ありがとうございます。確かにwhile文を抜けた後でもできますね。

Comment thread memo.md

if len(zigzag_levels) % 2 != 0:
zigzag_levels.append(list(reversed(current_level)))
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ここは階層の偶奇で場合分けしており対称性があるので、if-elseで書くほうが分かりやすいと感じました。

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.

ありがとうございます。実はif-elseで書くか迷いました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants