Mirror image of a binary tree

前端 未结 13 2538
时光取名叫无心
时光取名叫无心 2020-12-01 09:00

Suppose there is a tree:

             1
            / \\
           2   3
              / \\
             4   5

Then the mirror image will

13条回答
  •  日久生厌
    2020-12-01 09:10

    TreeNode * mirror(TreeNode *node){
      if(node==NULL){
        return NULL;
      }else{
        TreeNode *temp=node->left;
        node->left=mirror(node->right);
        node->right=mirror(temp);
        return node;
      }
    }
    

提交回复
热议问题