226. Invert Binary Tree 翻转二叉树
翻转一棵二叉树。
示例:
输入:
4/ \2 7/ \ / \ 1 3 6 9
输出:
4/ \7 2/ \ / \ 9 6 3 1
备注:
这个问题是受到 Max Howell 的 原问题 启发的 :
谷歌:我们90%的工程师使用您编写的软件(Homebrew),但是您却无法在面试时在白板上写出翻转二叉树这道题,这太糟糕了。
递归
这题,比较简单,看代码就能看懂。
Code
def invertTree(self, root: TreeNode) -> TreeNode:if root:self.invertTree(root.left)self.invertTree(root.right)root.right, root.left = root.left, root.rightreturn root
226. Invert Binary Tree 翻转二叉树相关推荐
- 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 ...
- 226. Invert Binary Tree 1
题目链接:Invert Binary Tree 思路: 如果需要反转一个二叉树,那么我们需要遍历整个树的所有节点. 如果想遍历所有的节点,我们可以用Depth First Search(DFS)或者B ...
- leetcode python3 简单题226. Invert Binary Tree
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百二十六题 (1)题目 英文: Invert a binary tree. 中文 ...
- 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 整理 ...
- [LeetCode][JavaScript]Invert Binary Tree 反转二叉树
反转二叉树 其实我从没有想到前端面试会问到这个问题,题目来源于google的面试 Google: 90% of our engineers use the software you wrote (Ho ...
- 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 思路分析: 题意是将二叉树所有左右子数 ...
- 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 ...
- Leetcode 226: Invert Binary Tree
问题描述: Given the root of a binary tree, invert the tree, and return its root. 将二叉树镜像 思路: 发现子问题:将给定二叉树 ...
- 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 ...
最新文章
- idea 高效找出全部未被使用的代码
- IP地址与字符串、整型之间的转换
- 利用jquery getJSON 调用ashx实现ajax调用
- 世界顶级的程序员们告诉你:这些书都是你应该读的
- Android 集成高德地图——当前定位,添加图标,画路线,设置显示中心位置,比例,地图刷新位置监听,判断GPS开启,去打开GPS
- jQuery操作cookie
- java 高效文本查找替换_Java 查找、高亮PDF 文本
- 动手学深度学习(PyTorch实现)(二)--softmax与分类模型
- 长假终结踏上归途 网络电话延续团圆亲情
- 3升5升得4升——倒水问题的万能解法(扩展欧几里得算法)
- MATLAB信号的带宽估计及求带宽(3dB,90%带宽)
- stm32F407中arr与psc以及pwm之间的关系
- 物联网NB-IoT技术商用正全面铺开 竞争日趋激烈
- ES6 极简教程(ES6 Tutorial) 文 / 东海陈光剑
- 大天使黎明服务器维护,37大天使之剑3月5日部分区服维护公告
- WCF 项目应用连载[9] - 契约中的委托 事件参数处理
- mvc原理和mvc模式的优缺点
- Python编程与其他编程语言相比有何优势?
- mvn Mac Linux 版本,Mac 下 Maven 的命令行安装
- 软件光盘制作教程之—菜鸟篇