Skip to content

Instantly share code, notes, and snippets.

@dendisuhubdy
Created October 27, 2015 00:53
Show Gist options
  • Save dendisuhubdy/e95fecaf5fc31c8f5d52 to your computer and use it in GitHub Desktop.
Save dendisuhubdy/e95fecaf5fc31c8f5d52 to your computer and use it in GitHub Desktop.
# 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