当前位置:网站首页>LeetCode226. 翻转二叉树
LeetCode226. 翻转二叉树
2022-06-28 20:59:00 【Yuyy】
本文最后更新于 484 天前,其中的信息可能已经有所发展或是发生改变。
一、思路
我还想着二叉树遍历(非递归)忘了呢,转念一想,这儿又没有要求不能用递归,递归它不香吗?
二、问题
翻转一棵二叉树。
示例:
输入:
4
/ \
2 7
/ \ / \
1 3 6 9输出:
4
/ \
7 2
/ \ / \
9 6 3 1备注: 这个问题是受到 Max Howell 的 原问题 启发的 :
谷歌:我们90%的工程师使用您编写的软件(Homebrew),但是您却无法在面试时在白板上写出翻转二叉树这道题,这太糟糕了。
Related Topics
- 树
\n
- 771
- 0
三、代码
public TreeNode invertTree(TreeNode root) {
if (root == null) {
return null;
}
TreeNode temp=root.left;
root.left = root.right;
root.right = temp;
root.left = invertTree(root.left);
root.right=invertTree(root.right);
return root;
}Post Views: 279
边栏推荐
- 数据资产为王,如何解析企业数字化转型与数据资产管理的关系?
- List of domestic database directory
- 【读书会第13期】视频文件的封装格式
- Binary tree problems
- 大智慧上怎么进行开户啊, 安全吗
- Relevant calculation of sphere, etc
- Characters and integers
- Query rewriting for opengauss kernel analysis
- ThreadLocal principle
- Is it safe for CICC fortune to open an account? Let's talk about CICC fortune
猜你喜欢

接口用例设计

【筆記:模擬MOS集成電路】帶隙基准(基本原理+電流模+電壓模電路詳解)

方 差 分 析
![[try to hack] cobalt strike (I)](/img/2b/5d274078b7d7ebd05b7c6d9e020868.png)
[try to hack] cobalt strike (I)
![[Note: circuit intégré MOS analogique] référence de bande Gap (principe de base + mode courant + circuit en mode tension)](/img/cd/be62272d465ca990456c222b38df67.png)
[Note: circuit intégré MOS analogique] référence de bande Gap (principe de base + mode courant + circuit en mode tension)

API 网关 Apache APISIX 助力雪球双活架构演进

Leetcode daily question - 515 Find the maximum value in each tree row

力扣树的进一步应用

On the complexity of software development and the way to improve its efficiency

Bitbucket 使用 SSH 拉取仓库失败的问题
随机推荐
穩定性總結
【筆記:模擬MOS集成電路】帶隙基准(基本原理+電流模+電壓模電路詳解)
Pyechart drawing multiple Y-axis line graphs
员工薪资管理系统
Application practice | 1billion data second level correlation. Huolala's OLAP System Evolution Based on Apache Doris (with PPT download)
[learning notes] factor analysis
Anr problem - camera related debug
视频号如何下载视频?来看超简单方法!
Globalsign's Pan domain SSL certificate
Anr analysis - question 1
How to analyze the relationship between enterprise digital transformation and data asset management?
券商公司开户哪个最靠谱最安全呢
Leetcode daily question - 30 Concatenate substrings of all words
Stability summary
Binary tree problems
oracle delete误删除表数据后如何恢复
Flask - Summary
List of domestic database directory
[learning notes] Introduction to principal component analysis
Relevant calculation of sphere, etc