剑指offer 27 二叉树的镜像

解题思路:递归

        1.交换左右结点,并交换左右子树中的左右节点

        

class Solution:
    def Mirror(self , pRoot: TreeNode) -> TreeNode:
        # write code here
        #前序遍历,交换树的左右结点
        if not pRoot:
            return
        
        pRoot.right, pRoot.left = pRoot.left, pRoot.right
        self.Mirror(pRoot.left)
        self.Mirror(pRoot.right)
        return pRoot

你可能感兴趣的:(二叉树,python,剑指offer,算法,数据结构)