1. Invert Binary Tree My Submissions QuestionEditorial Solution
    Total Accepted: 87818 Total Submissions: 193396 Difficulty: Easy
    Invert a binary tree.

    4
    / \
    2 7
    / \ / \
    1 3 6 9
    to
    4
    / \
    7 2
    / \ / \
    9 6 3 1
    逆转一颗二叉树
    思路:so easy

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     TreeNode *left;*     TreeNode *right;*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}* };*/
class Solution {
public:TreeNode* invertTree(TreeNode* root) {if(root==NULL)return NULL;TreeNode *tnode;tnode = root->left;root->left = root->right;root->right = tnode;invertTree(root->left);invertTree(root->right);return root;}
};

转载于:https://www.cnblogs.com/freeopen/p/5482932.html

37-Invert Binary Tree相关推荐

  1. [LeetCode] Invert Binary Tree - 二叉树翻转系列问题

    目录: 1.Invert Binary Tree - 二叉树翻转 [递归] 题目概述: Invert a binary tree. 4/ \2 7/ \ / \ 1 3 6 9 to 4/ \7 2/ ...

  2. 226. Invert Binary Tree 1

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

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

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

  4. leetcode(226)—— Invert Binary Tree(Python/C++)

    Invert Binary Tree 二叉树节点定义: struct TreeNode {int val;TreeNode *left;TreeNode *right;TreeNode(int x) ...

  5. 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 ...

  6. [LeetCode226]Invert Binary Tree

    题目: Invert a binary tree. 4/ \2 7/ \ / \ 1 3 6 9 to 4/ \7 2/ \ / \ 9 6 3 1 反转二叉树,左右儿子值交换 代码: /** * D ...

  7. [LeetCode][JavaScript]Invert Binary Tree 反转二叉树

    反转二叉树 其实我从没有想到前端面试会问到这个问题,题目来源于google的面试 Google: 90% of our engineers use the software you wrote (Ho ...

  8. 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 思路分析: 题意是将二叉树所有左右子数 ...

  9. Invert Binary Tree

    https://leetcode.com/problems/invert-binary-tree/ Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to ...

  10. C#LeetCode刷题之#226-翻转二叉树(Invert Binary Tree)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4080 访问. 翻转一棵二叉树. 输入: 4    /   \   ...

最新文章

  1. linux环境insight安装与使用
  2. 【目标检测系列】非极大值抑制(NMS)的各类变体汇总
  3. python初学--day1
  4. 物理生力热实验不确定度计算源代码
  5. 转 android anr 分析示例,[摘]Android ANR日志分析指南之实例解析
  6. 无线多串口服务器,多串口通信服务器
  7. ideal如何快速导入import_【MAC版】pr预设安装目录?pr如何快速批量导入lut
  8. C#事件(event)解析(转)
  9. Javascript: IE中命名函数直接量的Bug?
  10. 为什么 我的博客还没文章?
  11. Python:minicap实现快速截图
  12. 鼠标自动移动 防止锁屏睡眠
  13. 洛谷试炼场---提高历练地2
  14. java接口文档怎么写_如何写好API接口文档
  15. 我如何构建Pomodoro Clock应用程序,以及在此过程中学到的课程
  16. Android ADB原理及常用命令
  17. NEC Programming Contest 2021(AtCoder Beginner Contest 229) B - Hard Calculation
  18. 【技术类】【ArcGIS对国产卫星的支持2:高分一号卫星】篇7、大规模影像管理
  19. opencv2计算机视觉编程手册(中文)pdf
  20. 典型环节(或系统)的频率特性测量

热门文章

  1. 低配置系统安装 linux,Linux系统的安装和配置
  2. 怎么判断前轮左右的位置_如何判定汽车前面左右轮的位置?大家有什么经验?...
  3. python中的位置怎么看_如何知道项目在Python有序字典中的位置
  4. 休眠 关闭串口输出_C#实例:串口通讯
  5. 浮点卷积winograd算法
  6. Android编译错误: The project cannot be built until build path errors are resolved
  7. Android程序的基本组件
  8. UBoot讲解和实践-------------讲解(二)
  9. CF-1209 F. Koala and Notebook(建图BFS)
  10. 7624:山区建小学