快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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://6mz.cn/article/ppohge.html

其他资讯