题目 Invert a binary tree. 解题思路 使用递归的方法,假设子树已经操作完成,交换左右子树 代码 class Solution: def invertTree(self, root: TreeNode) -> TreeNode: if root: root.left, root.right = self.invertTree(root.right), self.invertTree(root.left) return root 视频讲解 YouTube<--欢迎点击订阅 视频讲解 bilibili<--欢迎点击订阅 Previous LeetCode 72 Edit Distance (Python) Next LeetCode 237 Delete Node in a Linked List (Python)