2021-08-26发表2021-08-26更新几秒读完 (大约93个字)leetcode-226226. 翻转二叉树描述翻转一棵二叉树。 示例: 输入: 12345 4 / \ 2 7 / \ / \1 3 6 9 输出: 12345 4 / \ 7 2 / \ / \9 6 3 1 解法参考题解 除此之外还可以用bfs。 1234567891011121314# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution: def invertTree(self, root: TreeNode) -> TreeNode: if root == None: return None left = self.invertTree(root.left) right = self.invertTree(root.right) root.right = left root.left = right return root leetcode-226http://example.com/2021/08/26/leetcode-226/作者bd160jbgm发布于2021-08-26更新于2021-08-26许可协议#二叉树