Skip to content

226 invert binary tree

226. Invert Binary Tree

题目: https://leetcode.com/problems/invert-binary-tree/

难度:

Easy

典型的递归题

class Solution(object):
    def invertTree(self, root):
        """
        :type root: TreeNode
        :rtype: TreeNode
        """
        if not root:
            return None
        self.invertTree(root.left)
        self.invertTree(root.right)
        root.left, root.right = root.right, root.left
        return root


回到顶部