Skip to content

617. Merge Two Binary Trees#23

Open
TakayaShirai wants to merge 1 commit intomainfrom
617_merge_two_binary_trees
Open

617. Merge Two Binary Trees#23
TakayaShirai wants to merge 1 commit intomainfrom
617_merge_two_binary_trees

Conversation

@TakayaShirai
Copy link
Copy Markdown
Owner

@TakayaShirai TakayaShirai self-assigned this Feb 14, 2026
Comment on lines +167 to +171
final mergedLeft = mergeNodes(source1?.left, source2?.left);
final mergedRight = mergeNodes(source1?.right, source2?.right);

parent.left = mergedLeft;
parent.right = mergedRight;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

そのまま代入してしまっても通じそうです。

Suggested change
final mergedLeft = mergeNodes(source1?.left, source2?.left);
final mergedRight = mergeNodes(source1?.right, source2?.right);
parent.left = mergedLeft;
parent.right = mergedRight;
parent.left = mergeNodes(source1?.left, source2?.left);
parent.right = mergeNodes(source1?.right, source2?.right);

一旦束縛したいのであれば、空行は無くても良さそうです。

Suggested change
final mergedLeft = mergeNodes(source1?.left, source2?.left);
final mergedRight = mergeNodes(source1?.right, source2?.right);
parent.left = mergedLeft;
parent.right = mergedRight;
final mergedLeft = mergeNodes(source1?.left, source2?.left);
final mergedRight = mergeNodes(source1?.right, source2?.right);
parent.left = mergedLeft;
parent.right = mergedRight;

Comment on lines +173 to +175
if (mergedLeft != null) {
mergeSourcesWithParent.add((source1?.left, source2?.left, mergedLeft));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

dart的なお作法に逆らわないのであれば、rightと対称にしたいです。

Suggested change
if (mergedLeft != null) {
mergeSourcesWithParent.add((source1?.left, source2?.left, mergedLeft));
}
if (mergedLeft != null) {
mergeSourcesWithParent.add((
source1?.left,
source2?.left,
mergedLeft,
));
}

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.

フォーマッターのオプションで固定できそうですかね。

ちなみに、Pythonのフォーマッターであるruffでは、末尾にカンマを入れると、取り除かれずにスレッド元のようなフォーマットになりました(つまりデフォルトの設定で、意図的に対称な形にできる)。dartではどうかわかりませんがご参考まで。

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