翻转二叉树(leetcode-226)

  • 递归得到叶子节点,从叶子节点开始依次到根节点进行翻转
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
    原文作者:满二叉树
    原文地址: https://blog.csdn.net/u013632190/article/details/51961518
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞