struct TreeNode* invertTree(struct TreeNode* root)
{ if ( NULL == root )
{
return NULL;
} if ( NULL == root->left && NULL == root->right )
{
//叶子节点
return root;
} //交换左右子节点
struct TreeNode * pTreeNodeTmp = root->left; root->left = root->right;
root->right = pTreeNodeTmp; invertTree(root->left);
invertTree(root->right); return root;
}

LeetCode —— Invert Binary Tree的更多相关文章

  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] 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 ...

  3. LeetCode——Invert Binary Tree

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

  4. LeetCode: Invert Binary Tree

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

  5. LeetCode Invert Binary Tree 反转二叉树

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

  6. leetcode Invert Binary Tree python

    # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...

  7. 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 ...

  8. <LeetCode OJ> 226. Invert Binary Tree

    226. Invert Binary Tree Total Accepted: 57653 Total Submissions: 136144 Difficulty: Easy Invert a bi ...

  9. Python解Leetcode: 226. Invert Binary Tree

    leetcode 226. Invert Binary Tree 倒置二叉树 思路:分别倒置左边和右边的结点,然后把根结点的左右指针分别指向右左倒置后返回的根结点. # Definition for ...

随机推荐

  1. ps制作gif图片

    本文自学内容来自这里 PS版本是CS6: 制作效果 步骤 1.下载素材 2.打开ps,添加素材 文件->打开->选择所有需要的素材全部打开(如图,已将需要的3个素材全部打开) 3.将素材放 ...

  2. js-格式化数字保留两位小数-带千分符

    很多时候发现有时候js会提示自带函数不能使用,所以自己找了很多资料实现了个 html <input type="text" class="input_text in ...

  3. PHP读取XML

    books.xml文件: 代码 <books> <book> <author>Jack Herrington</author> <title> ...

  4. 【CodeForces 699D】Fix a Tree

    dfs找出联通块个数cnt,当形成环时,令指向已访问过节点的节点变成指向-1,即做一个标记.把它作为该联通图的根. 把所有联通的图变成一颗树,如果存在指向自己的点,那么它所在的联通块就是一个树(n-1 ...

  5. JavaScript RegExp 对象(来自w3school)

    RegExp 对象用于规定在文本中检索的内容. 什么是 RegExp? RegExp 是正则表达式的缩写. 当您检索某个文本时,可以使用一种模式来描述要检索的内容.RegExp 就是这种模式. 简单的 ...

  6. Hadoop 权威指南学习2 (Sqoop)

    6. Sqoop Apache sqoop is an open source tool that allow users to extract data from structured data s ...

  7. 浅析VO、DTO、DO、PO的概念、区别和用处

    上一篇文章作为一个引子,说明了领域驱动设计的优势,从本篇文章开始,笔者将会结合自己的实际经验,谈及领域驱动设计的应用.本篇文章主要讨论一下我们经常会用到的一些对象:VO.DTO.DO和PO. 由于不同 ...

  8. 【poj1177】 Picture

    http://poj.org/problem?id=1177 (题目链接) 题意 求矩形周长并. Solution 转自:http://www.cnblogs.com/Booble/archive/2 ...

  9. c语言几种异常

    这几天写C程序,问题不断,先记下来吧 double free or corruption 字面意思理解为重复释放空间或崩溃,通常由于你调用了两次free,虽然你可能不是两次给free()传同一个指针, ...

  10. Android成长日记-ContextMenu实现上下文菜单

    一. ContextMenu的组成 标题以及标题图标 菜单内容 菜单内容的点击事件 二. ContextMenu与OptionMenu的区别 OptionMenu对应的是activity,一个acti ...