Simplest Solution Python Easy


def helper(root1,root2):
if(root1 == None and root2 == None):
return None
if(root1 == None):
return root2
if(root2 == None):
return root1
root = TreeNode(root1.val + root2.val)
root.left = helper(root1.left,root2.left)
root.right = helper(root1.right,root2.right)
return root

class Solution:
# @param A : root node of tree
# @param B : root node of tree
# @return the root node in the tree
def solve(self, A, B):
return helper(A,B)


Similar to mine but it ends -up in TLE , Any idea why ?