# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None class Solution(object):
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
if root is None:
return None
if root.left:
self.invertTree(root.left)
if root.right:
self.invertTree(root.right)
root.left,root.right=root.right,root.left
return root

leetcode Invert Binary Tree python的更多相关文章

  1. LeetCode—— Invert Binary Tree

    LeetCode-- Invert Binary Tree Question invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 ...

  2. Leetcode 226 Invert Binary Tree python

    题目: Invert a binary tree. 翻转二叉树. 递归,每次对节点的左右节点调用invertTree函数,直到叶节点. python中也没有swap函数,当然你可以写一个,不过pyth ...

  3. [LeetCode] Invert Binary Tree 翻转二叉树

    Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem wa ...

  4. [leetcode]Balanced Binary Tree @ Python

    原题地址:http://oj.leetcode.com/problems/balanced-binary-tree/ 题意:判断一颗二叉树是否是平衡二叉树. 解题思路:在这道题里,平衡二叉树的定义是二 ...

  5. LeetCode——Invert Binary Tree

    Description: Invert a binary tree. 4    /    \  2      7 /  \    /   \1   3   6   9 to 4 / \ 7 2 / \ ...

  6. LeetCode: Invert Binary Tree

    /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * Tre ...

  7. LeetCode Invert Binary Tree 反转二叉树

    思路:递归解决,在返回root前保证该点的两个孩子已经互换了.注意可能给一个Null. C++ /** * Definition for a binary tree node. * struct Tr ...

  8. LeetCode —— Invert Binary Tree

    struct TreeNode* invertTree(struct TreeNode* root) { if ( NULL == root ) { return NULL; } if ( NULL ...

  9. lc面试准备:Invert Binary Tree

    1 题目 Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 接口: public TreeNod ...

随机推荐

  1. iOS设计模式解析(二)抽象工厂方法

    抽象工厂方法:提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类 与工厂方法区别: 抽象工厂通过对象组合创建抽象产品.工厂通过类集成创建抽象产品 抽象工厂创建多系列产品.工厂创建一种产 ...

  2. git使用前配置

    1. git config --global user.name "Trey" 2. git config --global user.email 164355949@qq.com ...

  3. JFrame??

    swing的三个基本构造块:标签.按钮.文本字段.但需要个地方安放他们,并希望用户如何处理他们.JFrame类就是解决这个问题————它是一个容器,允许程序员把其他组件添加到它里面,把它们组织起来,并 ...

  4. Android周笔记(9.8-14)(持续更新)

    本笔记记录一周内的小知识点和一些心学习的Demo. 1.PopupWindow: new 一个activity_pop_window:id为popwindow的Button,id为hello123的T ...

  5. phpcms 调用全站最新发布数据

    phpcms模板标签没有调用全站最新发布的数据 所以参考phpcms本身自带的lists方法写了一个Countlists调用全站数据 /** * 全站最热 * @param $data */ publ ...

  6. @Html.ActionLink 添加样式 html标签

    @Html.ActionLink(item.MessageTitle, "Detail", "News",new { MessageId = item.Mess ...

  7. Google机器学习教程心得(一)

    Hello world Google Machine Learning Recipes 1 官方中文博客 http://chinagdg.org/2016/03/machine-learning-re ...

  8. 【Chromium中文文档】Chrome/Chromium沙箱 - 安全架构设计

    沙箱 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture/Sandbox.ht ...

  9. 如何用ATL创建ActiveX控件

    演示截图: 代码简介或代码解析: 如何用ATL创建ActiveX控件 实现了一个ActiveX控件,它在一个圆内部有个正多边形,当用户在多变形内部单击将会使多边形的边数在当前的基础上+1,在多变形外部 ...

  10. 习题3.10 约瑟夫环 josephus问题

    /* assume a header */ /* 双向循环链表 */ struct Node; typedef struct Node * PtrToNode; typedef PtrToNode L ...