/**
* 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. Node.js-Socket.IO【1】-身份验证

    Websocket身份验证失败的时候,希望向前台传输错误信息,但是Socket.IO目前最新版本1.4.6在后台使用 next(new Error('unauthorization')); 前端的代码 ...

  2. [IOS]译Size Classes with Xcode 6: One Storyboard for all Sizes

    Size Classes with Xcode 6: One Storyboard for all Sizes 为所有的尺寸准备一个Storyboard 我最喜欢的Xcode6的特性是新的size c ...

  3. Shell中的判断标志

    測試的標誌 代表意義 1. 關於某個檔名的『檔案類型』判斷,如 test -e filename 表示存在否 -e 該『檔名』是否存在?(常用) -f 該『檔名』是否存在且為檔案(file)?(常用) ...

  4. Unity3D优化总结(一)

    1.如使用碰撞器,简单的模型尽量使用自带的碰撞器如BoxCollider,少使用Mesh Collider. 2.如要使用Mesh Collider,可以做一个专用的模型(尽量少网格)做为Mesh C ...

  5. 使用CallableStatement的用法

    package Test; import java.sql.*; public class Test7 { public static void main(String[] args) { Conne ...

  6. 20145205 《Java程序设计》实验报告五:Java网络编程及安全

    20145205 <Java程序设计>实验报告五:Java网络编程及安全 实验要求 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.客户端中输入明文,利用DES算法加密,D ...

  7. Andriod如何更改应用程序小图标

    1.之前我们安装的第一个应用图标是这样的(如下图) 2.在eclipse左侧项目中找到res文件下的drawable-hdpi         3.把自己找的LOGO图标拖到文件中,之后会弹出一个消息 ...

  8. 四则运算之Right-BICEP测试

    Right-结果是否正确? 正确 B-是否所有的边界条件都是正确的? Conformance(一致性):值是否和预期的一致  是一致的 Ordering(顺序性):值是否如应该的那样 是 是有序或者无 ...

  9. 将博客从jekyll迁移到了hexo

    关于hexo和jekyll hexo和jekyll一样都是个静态网站生成工具,hexo是一个台湾小伙使用nodejs开发的,jekyll则是用ruby开发,github内置了jekyll,可以直接将j ...

  10. 【7集iCore3基础视频】7-7 Qt5.2.1安装

    Qt5.2.1安装包:http://pan.baidu.com/s/1dFbju0p 密码:yj8j 源视频:http://pan.baidu.com/s/1hsmEyyw 密码:8rm9