leetcode Same Tree python

# 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):
    def isSameTree(self, p, q):
        """
        :type p: TreeNode
        :type q: TreeNode
        :rtype: bool
        """
        if p == None and q == None:
            return True
        if p and q and p.val == q.val:
            return self.isSameTree(p.right,q.right) and self.isSameTree(p.left,q.left)
        return False

 

posted @ 2015-12-06 22:41  hao.ma  阅读(153)  评论(0编辑  收藏  举报