要求

  • 翻转一棵二叉树

实现

  • 翻转左右子树,交换左右子树的根节点
 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. go中semaphore(信号量)源码解读

    运行时信号量机制 semaphore 前言 作用是什么 几个主要的方法 如何实现 sudog 缓存 acquireSudog releaseSudog semaphore poll_runtime_S ...

  2. 前端er必须知道的Git地址及常用工具地址

    商城篇(找工作必练) 开源商城 推荐指数:5星,掌握了它,可以说,今后工作中的各种需求都不是问题,工作1~2年的也可以学习其中的思路(建议收藏). 这是一个集小程序/公众号/app为一体的商城系统,包 ...

  3. Python基础(十八):面向对象“类”第一课

    记住:编写函数就是"面向过程",编写类就是"面向对象".类也是很多同学的一大学习难点,因此我这里还是准备带着大家学习一下. 类和对象对比 对象 : 具有行为和属 ...

  4. SQLlite实现增删查改

    activity_main.xml文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android ...

  5. Erda MSP 系列 - 以服务观测为中心的 APM 系统设计:开篇词

    本文首发于 Erda 技术团队知乎账号,更多技术文章可点击 Erda 技术团队 作者:刘浩杨,端点科技 PaaS 技术专家,微服务治理和监控平台负责人,Apache SkyWalking PMC成员 ...

  6. 一次错误使用 go-cache 导致出现的线上问题

    话说一个美滋滋的上午, 突然就出现大量报警, 接口大量请求都响应超时了. 排查过程 查看服务器的监控系统, CPU, 内存, 负载等指标正常 排查日志, 日志能够响应的结果也正常. request.l ...

  7. SpringCloud(五)GateWay网关

    Config 分布式配置中心 概述 微服务意味着要将单体应用中的业务拆分成个个子服务,每个服务的粒度相对较小因此系统中会出现大量的服务 由于每个服务都需要必要的配置信息才能运行,所以一套集中式的.动态 ...

  8. 4-socket套接字编程

    socket套接字编程 目标:根据socket模块提供的接口函数,进行组合使用完成基于tcp或者udp的网络编程. 套接字:完成上述目标的一种编程手段,编程方案. 套接字分类: 流式套接字(sock_ ...

  9. php实现redis消息发布订阅

    基础介绍 Pub/Sub功能(means Publish, Subscribe)即发布及订阅功能 基于事件的系统中,Pub/Sub是目前广泛使用的通信模型,它采用事件作为基本的通信机制,提供大规模系统 ...

  10. hdu4560 不错的建图,二分最大流

    题意: 我是歌手 Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Subm ...