[LinkedIn] Mirror of a binary tree

Given a binary tree, return the mirror of it.

Very easy. Recursion

TreeNode mirror(TreeNode root) {
  if (root == NULL)
     return NULL;
  else {
    TreeNode newNode = new TreeNode(root.val);
    newNode->left = mirror(root->right);
    newNode->right = mirror(root->left);
    return newNode;
  }
}
posted on 2015-03-31 14:25  Seth_L  阅读(126)  评论(0编辑  收藏  举报