# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = Noneclass Solution:
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
if root is None:
return root
temp = root.left
root.left = root.right
root.right = tempself.invertTree(root.left) #递归
self.invertTree(root.right)
return root
leetcode - 226 - 翻转二叉树
最新推荐文章于 2024-08-06 14:39:33 发布