要求

  • 翻转一棵二叉树

实现

  • 翻转左右子树,交换左右子树的根节点
 1 class Solution {
2 public:
3 TreeNode* invertTree(TreeNode* root) {
4
5 if( root == NULL )
6 return NULL;
7
8 invertTree( root->left );
9 invertTree( root->right );
10 swap( root->left, root->right );
11
12 return root;
13 }
14 };

相关

  • 100 Same Tree
  • 101 Symmetric Tree
  • 222 Count Complete Tree Nodes
  • 110 Balanced Binary Tree

[刷题] 226 Invert Binary Tree的更多相关文章

  1. LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree

    258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ...

  2. 226. Invert Binary Tree(C++)

    226. Invert Binary Tree Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 ...

  3. C#版 - 226. Invert Binary Tree(剑指offer 面试题19) - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - 2 ...

  4. <LeetCode OJ> 226. Invert Binary Tree

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

  5. Python解Leetcode: 226. Invert Binary Tree

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

  6. 226. Invert Binary Tree 翻转二叉树

    [抄题]: Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 [暴力解法]: 时间分析: 空间分 ...

  7. leetcode 226 Invert Binary Tree 翻转二叉树

    大牛没有能做出来的题,我们要好好做一做 Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Tri ...

  8. 【LeetCode】226. Invert Binary Tree 翻转二叉树(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址: https://lee ...

  9. Leetcode 226. Invert Binary Tree

    Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 class Solution(object): ...

随机推荐

  1. Shell prompt(PS1) 与 Carriage Return(CR) 的关系?-- Shell十三问<第二问>

    Shell prompt(PS1) 与 Carriage Return(CR) 的关系?-- Shell十三问<第二问> 当你成功登录进一个文字界面之后,大部份情形下,你会在荧幕上看到一个 ...

  2. 3步安装Python虚拟环境virtualenv

    1. pip安装必要库 pip install virtualenv -i https://pypi.douban.com/simple pip install virtualenvwrapper - ...

  3. c 结构体内存对齐详解

    0x00简介 首先要知道结构体的对齐规制 1.第一个成员在结构体变量偏移量为0的地址处 2.其他成员变量对齐到某个数字的整数倍的地址处 对齐数=编辑器默认的一个对齐数与该成员大小的较小值 vs中默认的 ...

  4. (十二)struts2的类型转换

    所有的MVC框架,都属于表现层的解决方案,都需要负责收集用户请求参数,并将请求参数传给应用的控制器组件. 这时问题出现了,所有的请求参数都是字符串类型数据,因此MVC框架必须具备将这些字符串请求参数转 ...

  5. pwnable.tw 3x17

    3x17 文章主要是参考了https://xuanxuanblingbling.github.io/ctf/pwn/2019/09/06/317/ 首先我们检查一下开启的保护 运行一下,先让输入add ...

  6. 自动化kolla-ansible部署centos7.9+openstack-train-超融合高可用架构

    自动化kolla-ansible部署centos7.9+openstack-train-超融合高可用架构 欢迎加QQ群:1026880196 进行交流学习 环境说明: 1. 满足一台电脑一个网卡的环境 ...

  7. 网络编程Netty入门:责任链模式介绍

    目录 责任链模式 责任链模式的简单实现 Netty中的ChannelPipeline责任链 服务端接收客户端连接 pipeline初始化 入站事件和出站事件 Pipeline中的Handler Pip ...

  8. Jmeter接口测试-MD5加密-请求验签(完整流程)

    第一部分:先准备好Jmeter 1.在开始编写脚本之前,先要确保你的Jmeter能够正常运行.若你还没有安装Jmeter,可参考以下方法: A.Jmeter需要java运行环境,所以需要下载JDK,J ...

  9. 1- MySQL数据库基础快速入门

    我们进行不管是软件开发还是软件测试相关的职业的时候数据库必不可少:下面从数据库的概念开始了解,大家三四天的时间就可以完全掌握数据库的基本用法,然后多练习. 什么是数据,数据库 -数据是数据库中存储的基 ...

  10. 16- web测试总结

    在线用户不进行任何操作,对服务器也会产生压力.因为有会话的存在. 服务器tps与相应时间没有直接关系:每个口 关键性能指标:TPS.响应时间.并发数.思考时间.资源利用率(内存.cpu.磁盘).pv. ...