[Given a binary tree, how do you remove all the half nodes?]
defRemoveHalfNodes(root):if root isNone:returnNone root.left =RemoveHalfNodes(root.left) root.right =RemoveHalfNodes(root.right)# if both left and right child is None # the node is not a Half nodeif root.left isNoneand root.right isNone:return root# If current nodes is a half node with left child# None then it's right child is returned and # replaces it in the given treeif root.left isNone: new_root = root.right temp = root root =Nonedel(temp)return new_rootif root.right isNone: new_root = root.left temp = root root =Nonedel(temp)return new_rootreturn root