/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public TreeNode invertTree(TreeNode root) {
if (root == null) return null;
TreeNode tmp = root.left;
root.left = invertTree(root.right);
root.right = invertTree(tmp);
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 反转二叉树

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

  5. leetcode Invert Binary Tree python

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

  6. LeetCode —— Invert Binary Tree

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

  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. Codeforces558E A Simple Task(线段树)

    题目 Source http://codeforces.com/problemset/problem/558/E Description This task is very simple. Given ...

  2. PHP生成验证码及单实例应用

    /* note: * this 指向当前对象本身 * self 指向当前类 * parent 指向父类 */ /* 验证码工具类 * @author pandancode * @date 20150- ...

  3. PHP遍历、删除文件夹中的所有文件

    <?php header("Content-type:text/html;charset=utf-8"); /** * getDirFile 遍历文件夹中的所有文件 * @p ...

  4. View基础知识

    一.View基础知识 View 是Android中所有控件的基类,是一种界面层的控件的一种抽象,代表了一个控件 1.View的位置参数 View的四个属性:top(左上角纵坐标)     left(左 ...

  5. Ubuntu14.04安装wineqq国际版

       一开始,我在Ubuntu14.04下安装的QQ版本是WineQQ2013SP6-20140102-Longene, 但后来发现这个版本QQ在linux下问题很多,比如不能用键盘输入密码,QQ表情 ...

  6. Java中线程的生命周期

    首先简单的介绍一下线程: 进程:正在运行中的程序.其实进程就是一个应用程序运行时的内存分配空间. 线程:其实就是进程中的一条执行路径.进程负责的是应用程序的空间的标示.线程负责的是应用程序的执行顺序. ...

  7. C++11 auto and decltype

    1.auto关键字 C++新标准引入auto关键词,此auto与之前C语言的auto意义已经不一样了. 这里的auto是修饰未知变量的类型,编译器会通过此变量的初始化自动推导变量的类型. 例如:aut ...

  8. html文本的基本设置

    一.字体属性: 选择字体:font-family:value,value....指定字体的显示,按照顺序直到能够匹配 字体的大小:font-size:39px: 字体加粗:font-weight:bo ...

  9. 在eclipse中创建一个Maven项目

    1. 首先判断eclipse有没有自带Maven Window –> Perferences 如果有Maven,那就是自带了maven插件,如果没有,需要自行安装. 2.配置maven 2.1. ...

  10. win7+vs2008+windows mobile6.5.3

    1.安装vs2008+vs2008sp12.安装Windows Mobile 6 Professional SDK Refresh.msi3.安装Windows Mobile 6 Profession ...