Skip to content

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

Open
irohafternoon wants to merge 1 commit intomainfrom
103.-Binary-Tree-Zigzag-Level-Order-Traversal
Open

Create 103. Binary Tree Zigzag Level Order Traversal.md#30
irohafternoon wants to merge 1 commit intomainfrom
103.-Binary-Tree-Zigzag-Level-Order-Traversal

Conversation

@irohafternoon
Copy link
Copy Markdown
Owner

next_nodes.push_back(node->right);
}
}
std::swap(current_nodes, next_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.

個人的には、next_nodescurrent_nodesに渡す時点でreverseさせておきたくなります。

与えられた配達リストを奇数日なら後ろから配達して、偶数日なら上から配達してくださいという依頼にみえます。上から配達してもらうための配達リストを渡すのが自然だと思います。

}
return zigzag_ordered_lists;
}
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

いいと思います

std::vector<TreeNode*> next_nodes;
zigzag_ordered_values.emplace_back();
for (auto node : current_nodes) {
zigzag_ordered_values[current_level].push_back(node->val);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

.back() で最後尾へのリファレンスが取れます。

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.

ありがとうございます。
リファレンスを確認しました
https://cplusplus.com/reference/vector/vector/back/

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.

3 participants