当前位置:网站首页>Leetcode brush questions: binary tree 05 (flip binary tree)
Leetcode brush questions: binary tree 05 (flip binary tree)
2022-07-04 04:20:00 【Taotao can't learn English】
226. Flip binary tree
Turn over a binary tree .

package com.programmercarl.tree;
/** * @ClassName InvertTree * @Descriotion TODO * @Author nitaotao * @Date 2022/7/3 12:57 * @Version 1.0 * https://leetcode.cn/problems/invert-binary-tree/ * 226. Flip binary tree **/
public class InvertTree {
public TreeNode invertTree(TreeNode root) {
invert(root);
return root;
}
public void invert(TreeNode root) {
if (root == null) {
return;
}
TreeNode temp = root.left;
root.left = root.right;
root.right = temp;
invertTree(root.left);
invertTree(root.right);
}
}

There is one saying. , I'll take this question , Again AC, I didn't arrive for three minutes from beginning to end . I'm confused after writing .
Do with recursion
- First judge whether the current node is empty
- Exchange left and right nodes
- Enter the left node and perform this step
- Enter the right node and perform this step
- Finally, let's look at the solution

You scared me ... Look again quickly .
边栏推荐
- [csrf-01] basic principle and attack and defense of Cross Site Request Forgery vulnerability
- (指针)编写函数void fun(int x,int *pp,int *n)
- The maximum expiration time of client secret in azure ad application registration is modified to 2 years
- Katalon中控件的参数化
- Three years of graduation, half a year of distance | community essay solicitation
- Redis cluster uses Lua script. Lua script can also be used for different slots
- The difference between bagging and boosting in machine learning
- There is a problem that the package cannot be parsed in the like project
- STM32外接DHT11显示温湿度
- C语言双向链表初版
猜你喜欢

Tcpclientdemo for TCP protocol interaction

Flink学习7:应用程序结构

Unity 绘制弹球和台球的运动轨迹

leetcode刷题:二叉树07(二叉树的最大深度)

软件测试是干什么的 发现缺陷错误,提高软件的质量

ctf-pikachu-XSS

Understand the principle of bytecode enhancement technology through the jvm-sandbox source code

Evolution of MySQL database architecture

leetcode刷题:二叉树06(对称二叉树)

干货!基于GAN的稀有样本生成
随机推荐
(指針)自己寫一個比較字符串大小的函數,功能與strcmp類似。
Brief explanation of depth first search (with basic questions)
Storage of MySQL database
图解网络:什么是热备份路由器协议HSRP?
[paddleseg source code reading] normalize operation of paddleseg transform
There is a problem that the package cannot be parsed in the like project
[webrtc] M98 Ninja build and compile instructions
Redis cluster view the slots of each node
My opinion on how to effectively telecommute | community essay solicitation
Support the first triggered go ticker
Flink learning 6: programming model
软件测试是干什么的 发现缺陷错误,提高软件的质量
Penetration practice - sqlserver empowerment
vim映射命令
One click compilation and deployment of MySQL
Katalon使用script实现查询List大小
Flink学习8:数据的一致性
[microservice openfeign] use openfeign to remotely call the file upload interface
leetcode刷题:二叉树09(二叉树的最小深度)
LNK2038 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MDd_DynamicDebug”(main.obj 中)