Easy understandable preorder traversal python solution

programming
Tags: #<Tag:0x00007f24259df8f0>

#1
      def Merge(a,b):
        a.val = a.val + b.val
        if a.left and b.left:
            Merge(a.left,b.left)
        if a.right and b.right:
            Merge(a.right,b.right)
        if not a.left and b.left:
            a.left = b.left
        if not a.right and b.right:
            a.right = b.right
    if not A:
        return B
    if A:
        if B:
            Merge(A,B)
        return A

#2

Hello,
This is not a readable solution. For Python code, you must use indentation.


#3

sorry I have edited the solution. I thought I have pasted the formatted code


#4

you are simply superbbb.Intelligent coder