当前位置:网站首页>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
边栏推荐
- 【学习笔记】主成分分析法介绍
- API gateway Apache APIs IX helps the evolution of snowball dual active architecture
- How to use dataant to monitor Apache apisex
- How do I download videos? Look at the super simple method!
- 稳定性总结
- Win 10 create a gin framework project
- ref属性,props配置,mixin混入,插件,scoped样式
- On the complexity of software development and the way to improve its efficiency
- How to open an account in great wisdom? Is it safe
- 题解 Ananagrams(UVa156)紫书P113map的应用
猜你喜欢

应用实践 | 10 亿数据秒级关联,货拉拉基于 Apache Doris 的 OLAP 体系演进(附 PPT 下载)

Win 10 create a gin framework project

方 差 分 析

Ref attribute, props configuration, mixin mixing, plug-in, scoped style

Lucene构建索引的原理及源代码分析

基于 Apache APISIX 的自动化运维平台

LeetCode每日一题——515. 在每个树行中找最大值

数据资产为王,如何解析企业数字化转型与数据资产管理的关系?
How to recover after Oracle delete accidentally deletes table data

Leetcode 36. 有效的数独(可以,一次过)
随机推荐
pyechart绘制多条y轴折线图
Anr analysis - question 1
LeetCode每日一题——30. 串联所有单词的子串
Leetcode daily question - 30 Concatenate substrings of all words
List of domestic database directory
基于 Apache APISIX 的自动化运维平台
方 差 分 析
阿里云 MSE 基于 Apache APISIX 的全链路灰度方案实践
Is the rapid SSL wildcard certificate genuine in 1981
Ref attribute, props configuration, mixin mixing, plug-in, scoped style
Résumé de la stabilité
LeetCode560. 和为K的子数组
Is it safe to open a dig money account? Is it reliable?
【Try to Hack】Cobalt Strike(一)
输入和输出实型数据
Pie (poj3122) super detailed and easy to understand binary introduction
The principle and source code analysis of Lucene index construction
How to do a good job in customer's successful bottom design | tob Master Course
Alibaba cloud MSE full link grayscale solution practice based on Apache apisik
resilience4j 重试源码分析以及重试指标采集