Invert a tree to its mirror image

Ideas

The mirror image of the tree refers to the other tree obtained by exchanging non-leaf nodes, the left subtree, and the right subtree.

BinaryTreeNode mirrorOfBinaryTreeNode(BinaryTreeNode root){
    
    
  BinaryTreeNode temp;
  if(root != null){
    
    
    mirrorOfBinaryTreeNode(root.getRight());
    mirrorOfBinaryTreeNode(root.getLeft());
    temp = root.getLeft();
    root.setLeft(root.getRight());
    root.setRight(temp);
  }
  return root;
}

Guess you like

Origin blog.csdn.net/weixin_37632716/article/details/114550185