leetcode--翻转二叉树

翻转一棵二叉树。

共青城网站建设公司创新互联建站,共青城网站设计制作,有大型网站制作公司丰富经验。已为共青城成百上千提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的共青城做网站的公司定做!

示例:

输入:

     4
   /   \
  2     7
 / \   / \
1   3 6   9

输出:

     4
   /   \
  7     2
 / \   / \
9   6 3   1
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def invertTree(self, root: TreeNode) -> TreeNode:
        if root:
            root.left, root.right = root.right, root.left
            self.invertTree(root.left)
            self.invertTree(root.right)
        return root

执行用时 : 52 ms, 在Invert Binary Tree的Python3提交中击败了87.75% 的用户

内存消耗 : 13.1 MB, 在Invert Binary Tree的Python3提交中击败了65.41% 的用户


网页标题:leetcode--翻转二叉树
标题网址:http://lszwz.com/article/ppohge.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款