Skip to content

Create 1st.md#6

Open
kzhra wants to merge 4 commits into
mainfrom
226.-Invert-Binary-Tree
Open

Create 1st.md#6
kzhra wants to merge 4 commits into
mainfrom
226.-Invert-Binary-Tree

Conversation

@kzhra

@kzhra kzhra commented Jul 12, 2024

Copy link
Copy Markdown
Owner

@hayashi-ay hayashi-ay left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

良いと思います。PRのタイトルで問題が分かるようになっていると嬉しいです。

個人的には先に子について処理してから、自身をswapする方が処理を脳内でトレースしやすいですが、好みですかねー

Comment thread 2nd.md
}

swap(root->left, root->right);
if (root->left) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

この条件なくても動きますかね。

Comment thread 2nd.md

while (!unvisited.empty()) {
TreeNode* current = unvisited.front();
unvisited.pop();

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 にいれてしまって、ここで、current の nullptr チェックをする手もあります。

Comment thread 1st.md
current_node->right = nullptr;
node_queue.push(current_node->left);
} else {
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.

このelse説は不要そうですね

Comment thread 4th.md
TreeNode* current = unvisited.front();
unvisited.pop();

if (current) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

currentがnullptrだったら早めに抜けてあげることで、ネストを浅くできると思います。

if (current) {
  continue;
}

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.

4 participants