LeetCode Top100:反转二叉树
程序员文章站
2024-03-26 13:29:17
...
class Solution(object):
def invertTree(self, root):
if not root:
return root
temp=TreeNode()
temp.left=root.left
root.left=root.right
root.right=temp.left
self.invertTree(root.left)
self.invertTree(root.right)
return root