思路:就是将节点的左指针指向右孩子,右指针指向左孩子,递归即可实现;

/*** 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 *temp=root->left;root->left=invertTree(root->right);root->right=invertTree(temp);return root;}
};

Leetcode每日一题: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 翻转二叉树

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

  3. LeetCode 226. Invert Binary Tree--反转二叉树--C++,Python解法--递归,迭代做法

    题目地址:Invert Binary Tree - LeetCode Invert a binary tree. Example: Input: 4/ \2 7/ \ / \ 1 3 6 9 Outp ...

  4. 226. Invert Binary Tree 1

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

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

  7. Leetcode 226: Invert Binary Tree

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

  8. leetcode python3 简单题110. Balanced Binary Tree

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

  9. Leetcode-标签为Tree 226. Invert Binary Tree

    原题 Invert a binary tree. 4/ \ 2 7/ \ / \ 1 3 6 9 to 4/ \ 7 2/ \ / \ 9 6 3 1 代码分析 反转二叉树 代码实现 public T ...

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

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

最新文章

  1. linux下备份mysql上传到网盘_Linux命令行上传文件到百度网盘
  2. 一起聊聊好玩的Openresty
  3. php 时间 插件,PHP中Carbon日期时间处理利器详解
  4. android dialog 隐藏状态栏_Android开发不得不收集的工具类集合
  5. 自带的数据集_机器学习练习数据哪里找?两行代码搞定!
  6. 江苏涟水中学2021高考成绩查询,2021年涟水县高考状元名单资料,今年涟水县高考状元多少分...
  7. MyEclipse导入jquery-1.8.0.min.js等文件报错的解决方案
  8. Unfair contest(个人做法)
  9. 【Linux】Linux按tab键补全文件(名)或路径不区分大小写
  10. Bailian2801 填词 POJ1629 ZOJ1546 Fillword【排序】
  11. GridView常见问题及解决办法
  12. 前端设备通过Ehome协议接入EasyCVR平台无法播放问题解决
  13. matlab菲涅尔衍射光强分布,求助!!!用颜色表示的菲涅尔衍射的光强分布图
  14. matlab 低级图形错误,matlab图形底层错误(matlab崩溃前的数据恢复)
  15. 【Seen看世界】:像高智商人群看齐
  16. 心率检测实现报告(三)
  17. [2018 CS:GO Server]2018 Old CSGO 服务端,回忆逝去的青春!
  18. 仓库无证如何处罚_无证经营一般是怎么处罚的啊
  19. java 设计模式 路由器_Java设计模式——工厂模式
  20. FL Studio2022水果编曲音乐制作软件自带完整插件

热门文章

  1. 【ubuntu】更换下载源
  2. BZOJ 1070: [SCOI2007]修车(费用流)
  3. javascript怎么禁用浏览器后退按钮
  4. 读书笔记 - 《软件业的成功奥秘》
  5. 面向对象(类,面向对象三大特性)
  6. 用正则表达式输出rdf文档的三元组格式数据
  7. ASP.NET-关于Global.asax的作用
  8. Android中如何获取应用版本号
  9. Mysql支持中文全文检索的插件mysqlcft-应用中的问题
  10. SSLOJ 1335.蛋糕切割