- 递归得到叶子节点,从叶子节点开始依次到根节点进行翻转
class Solution(object):
@classmethod
def invertTree(self, root):
if root == None:
return None
else:
root.left = Solution.invertTree(root.left)
root.right = Solution.invertTree(root.right)
root.left, root.right = root.right, root.left
return root