leetcode -- Invert Binary Tree -- 简单题目看看

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

交换左右指针就行。

class Solution(object):
    def invert(self, root):
        if root:
            root.left, root.right = root.right, root.left
            self.invertTree(root.left)
            self.invertTree(root.right)

    def invertTree(self, root):
        """ :type root: TreeNode :rtype: TreeNode """
        self.invert(root)
        return root

你可能感兴趣的:(LeetCode)