Using Inorder Traversal and recursion , Python code


#1

class Solution:
# @param A : root node of tree
# @param B : root node of tree
# @return an integer
def isSameTree(self, A, B):
if self.inorder_t(A,’’) == self.inorder_t(B,’’):
return 1
return 0

def inorder_t(self,root,traversal):
    if root:
        traversal = self.inorder_t(root.left,traversal)
        traversal += str(root.val)
        traversal = self.inorder_t(root.right,traversal)
    return traversal