Removes all nodes with only one child and returns new root ( note that root may change )
def RemoveHalfNodes ( root ) : NEW_LINE INDENT if root is None : NEW_LINE INDENT return None NEW_LINE DEDENT root . left = RemoveHalfNodes ( root . left ) NEW_LINE root . right = RemoveHalfNodes ( root . right ) NEW_LINE if root . left is None and root . right is None : NEW_LINE INDENT return root NEW_LINE DEDENT DEDENT