Skip to content

617. Merge Two Binary Trees#22

Open
n6o wants to merge 1 commit intomainfrom
merge-two-binary-trees
Open

617. Merge Two Binary Trees#22
n6o wants to merge 1 commit intomainfrom
merge-two-binary-trees

Conversation

@n6o
Copy link
Owner

@n6o n6o commented Feb 23, 2026

- 片方が null ノードの場合、そこでマージ作業はストップできる
- null じゃないほうの木を返せばいい
- ノード数をn1, n2とすると
- 時間計算量は O(min(n1, n2))
Copy link

Choose a reason for hiding this comment

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

戻り値(成果物)の一部として入力の木(の一部)を使うのであればこうなりますね。そうでなければ max になりそうですね。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。

そうですね、木のコピーをする場合は大きい方の木を走査することになるので max になります。

@mamo3gr
Copy link

mamo3gr commented Feb 27, 2026

入力と異なるインスタンスを生成して返すパターンも検討すると、学びがより深まると思いました。

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