We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d51048e commit 7c7b988Copy full SHA for 7c7b988
Salesforce/Problem#422.py
@@ -0,0 +1,13 @@
1
+"""
2
+Write a program to merge two binary trees. Each node in the new tree should hold a
3
+value equal to the sum of the values of the corresponding nodes of the input trees.
4
+If only one input tree has a node in a given position, the corresponding node in
5
+the new tree should match that input node.
6
7
+def mergeTrees(t1: TreeNode, t2: TreeNode) -> TreeNode:
8
+ if not t1 or not t2:
9
+ return t1 or t2
10
+ t1.val += t2.val
11
+ t1.left = mergeTrees(t1.left, t2.left)
12
+ t1.right = mergeTrees(t1.right, t2.right)
13
+ return t1
0 commit comments