Skip to main content

🟢 剑指 Offer 27. 二叉树的镜像

LeetCode 提示

题目难度 简单

原题链接 🔗 leetcode

题解 1.py#

# 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:        if root is None:            return root        root.left, root.right = self.mirrorTree(root.right), self.mirrorTree(root.left)        return root