问题描述
https://leetcode.cn/problems/invert-binary-tree/description/
解题思路
没啥好说的,python的交换简单极了。
代码
# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: if root is not None: root.left, root.right = root.right, root.left self.invertTree(root.left) self.invertTree(root.right) return root
标签:right,val,invertTree,反转,self,二叉树,226,root,left From: https://www.cnblogs.com/bjfu-vth/p/17071013.html