、
翻转一棵二叉树。
示例:
输入:
4 / \ 2 7 / \ / \ 1 3 6 9
class Solution: def invertTree(self, root: TreeNode) -> TreeNode: if not root:return None#函数的终止条件是空的时候 #它要做的事情就是同时对左右子树进行处理 root.left,root.right=self.invertTree(root.right),self.invertTree(root.left) return root#最后还要返回的是原来的树,所以依然是树的根节点