原题

Invert a binary tree.

     4/   \
  2     7/ \   / \
1   3 6   9

to

     4/   \
  7     2/ \   / \
9   6 3   1

代码分析

反转二叉树

代码实现

        public TreeNode InvertTree(TreeNode root){if (root == null)return null;var tmp = root.left;root.left = root.right;root.right = tmp;InvertTree(root.left);InvertTree(root.right);return root;}

Leetcode-标签为Tree 226. Invert Binary Tree相关推荐

  1. leetcode python3 简单题226. Invert Binary Tree

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百二十六题 (1)题目 英文: Invert a binary tree. 中文 ...

  2. 226. Invert Binary Tree 1

    题目链接:Invert Binary Tree 思路: 如果需要反转一个二叉树,那么我们需要遍历整个树的所有节点. 如果想遍历所有的节点,我们可以用Depth First Search(DFS)或者B ...

  3. leetcode 226. Invert Binary Tree

    Invert a binary tree. 4/ \2 7/ \ / \ 1 3 6 9 to 4/ \7 2/ \ / \ 9 6 3 1 解法1: 本质是输的先序遍历 # Definition f ...

  4. Leetcode 226: Invert Binary Tree

    问题描述: Given the root of a binary tree, invert the tree, and return its root. 将二叉树镜像 思路: 发现子问题:将给定二叉树 ...

  5. LeetCode #226 - Invert Binary Tree - Easy

    Problem Invert a binary tree. Example 4/ \2 7/ \ / \ 1 3 6 9->4/ \7 2/ \ / \ 9 6 3 1 Algorithm 整理 ...

  6. Leet Code OJ 226. Invert Binary Tree [Difficulty: Easy]

    题目: Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 思路分析: 题意是将二叉树所有左右子数 ...

  7. 226. Invert Binary Tree

    做法就是: 如果root是null,返回 swap左右两树(用tmp作为第三个容器),然后对左右子树递归 返回root 1 public TreeNode invertTree(TreeNode ro ...

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

    翻转一棵二叉树. 示例: 输入: 4/ \2 7/ \ / \ 1 3 6 9 输出: 4/ \7 2/ \ / \ 9 6 3 1 备注: 这个问题是受到 Max Howell 的 原问题 启发的 ...

  9. java实现翻转二叉树_【leetcode刷题】[简单]226. 翻转二叉树(invert binary tree)-java...

    翻转二叉树 invert binary tree 题目 翻转一棵二叉树. 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 ...

最新文章

  1. max_semi_space_size 设置值与实际值不一致的原因分析
  2. msm8953+android8.1蓝牙名称修改、多产品采用不同名字的兼容
  3. k8s API编程:kubebuilder实战案例sidecarset
  4. 启明云端分享|sigmastar SSD201/ssd202核心板升级参考,可实现开机自动从 SD 卡升级固件或开机自动从 SD 卡烧录 MAC 地址
  5. ERROR 1093 解决方法
  6. 04-树7 二叉搜索树的操作集(c语言实现)
  7. MAC 安装 xctool 遇到的问题
  8. JavaFX UI控件教程(十二)之List View
  9. 创建Sonarqube项目
  10. SQL Cookbook:二、查询结果排序(1)以指定的次序返回查询结果
  11. C#无法生成解决方案,System.InvalidOperationException: 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分。
  12. frp ---- golang编写的内网穿透工具简介
  13. 配置在一台三层交换上,不同VLAN相互通信
  14. 基于Matlab的极限学习机(ELM)实现
  15. ET框架---UnityWebRequestAsync学习笔记
  16. 电脑连接SONY蓝牙耳机没有声音
  17. 互联网公司刻板印象合集:程序员都秃头,商务个个是人精
  18. w7查看计算机每天开关机时间,win7系统开机时间怎么看?查看win7开机时间的方法...
  19. 云计算机基地有辐射吗,孕妇离电脑多远没有辐射
  20. 如何去掉图片上的水印而不损图片

热门文章

  1. 华为一碰传nfc标签_一碰传连接失败,触碰标签无反应
  2. ZigBee2节干电池工作半年分析估算
  3. docker进入容器的方法
  4. 【Qt 中出现 No such slot 错误 解决方法】
  5. 【实体类】如何快速生成实体类?
  6. html框架和框架布局实战
  7. ChatGPT 镜像网站,无需账号,无地区限制!
  8. 185-186 抽象类+接口案例/运动员和教练
  9. 昆仑linux软件著作权,基于开源软件著作权
  10. 第二章 大数据如此重要,引无数英雄竞折腰