Created
February 27, 2018 19:44
-
-
Save dilanshah/c1bbae1f767b8a91431d20ebdd522d70 to your computer and use it in GitHub Desktop.
Leetcode 617. Merge Two Binary Trees. Given two binary trees and 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def mergeTrees(self, t1, t2): | |
""" | |
:type t1: TreeNode | |
:type t2: TreeNode | |
:rtype: TreeNode | |
""" | |
if not t1: | |
return t2 | |
elif not t2: | |
return t1 | |
t1.val += t2.val | |
t1.left = self.mergeTrees(t1.left, t2.left) | |
t1.right = self.mergeTrees(t1.right, t2.right) | |
return t1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment