Created
October 27, 2015 00:53
-
-
Save dendisuhubdy/e95fecaf5fc31c8f5d52 to your computer and use it in GitHub Desktop.
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
# Definition for a binary tree node. | |
class TreeNode(object): | |
def __init__(self, x): | |
self.val = x | |
self.left = None | |
self.right = None | |
class Solution(object): | |
p = TreeNode(1) | |
q = TreeNode(1) | |
def isSameTree(self, p, q): | |
""" | |
:type p: TreeNode | |
:type q: TreeNode | |
:rtype: bool | |
""" | |
if (p==q): | |
return True | |
elif (not p and not q): | |
return False | |
return ((p.val == q.val) and isSameTree(p.left, q.left) and isSameTree(p.right, q.right)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment