arrow_back Back to Challenges

#617 Merge Two Binary Trees

Easy Acceptance 0%
description

Problem Description

You are given two binary trees `root1` and `root2`. Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. Return the merged tree.

checklist Constraints

The number of nodes in both trees is in the range [0, 2000].
-10^4 <= Node.val <= 10^4

science Examples

Case #1

In: root1 = [1,3,2,5] root2 = [2,1,3,null,4,null,7]
Out: [3,4,5,5,4,null,7]

Case #2

In: root1 = [1] root2 = [1,2]
Out: [2,2]

Mastery Tags

Recursion Trees

Hiring Companies

Amazon Google Meta
code

Integrated IDE

code_blocks
Coding
psychology
Aptitude