Children Sum Property

def changeTree(root): 
if root ==None:
return
left=0
right=0
if root.left!=None:
if root.left.data<root.data:
root.left.data=root.data
changeTree(root.left)
left=root.left.data
if root.right!=None:
if root.right.data<root.data:
root.right.data=root.data
changeTree(root.right)
right=root.right.data
if not (root.left==None and root.right==None):
root.data=left+right

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.