Skip to content

Create binary-tree-zigzag-level-order-traversal.md#17

Open
tshimosake wants to merge 1 commit intomasterfrom
tshimosake-patch-15
Open

Create binary-tree-zigzag-level-order-traversal.md#17
tshimosake wants to merge 1 commit intomasterfrom
tshimosake-patch-15

Conversation

@tshimosake
Copy link
Owner

result.append(list(current_values))
left_to_right = not left_to_right
return result
```
Copy link

Choose a reason for hiding this comment

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

読みやすいと思いました。
計算量を考えてみてもよいかもしれません。

Choose a reason for hiding this comment

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

読みやすいと思いました。

current_level_size = len(queue)
current_level_vals = []
next_level_nodes = []
for _ in range(current_level_size):

Choose a reason for hiding this comment

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

一回しか呼ばないならlen(queue)のままでも良いのかなと思いました

return res
```

2回目

Choose a reason for hiding this comment

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

もっと幅広い解法があるので、Discordで探してみても良いと思いました。
例えばreverseを使ったり、Noneを許容してからFilterしたりといった方法も選択肢の幅としてありそうです。

while queue:
current_level_size = len(queue)
current_level_values = deque()
for _ in range(current_level_size):
Copy link

Choose a reason for hiding this comment

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

サイズを使って2つの階層を同じキューに入れて BFS するのは、私の趣味ではないのですが、しかし趣味の範囲かもしれません。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.ho7q4rvwsa1g

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.

5 participants