题目链接:https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/
难度:简单
描述:
请完成一个函数,输入一个二叉树,该函数输出它的镜像。
题解
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def mirrorTree(self, root: TreeNode) -> TreeNode:
def recursion(root):
if root is None:
return
root.left, root.right = root.right, root.left
recursion(root.left)
recursion(root.right)
recursion(root)
return root