当前位置:网站首页>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 .
边栏推荐
- Lnk2038 detected a mismatch of "runtimelibrary": the value "md_dynamicrelease" does not match the value "mdd_dynamicdebug" (in main.obj)
- Is it safe to buy insurance for your children online? Do you want to buy a million dollar medical insurance for your children?
- 毕业三年,远程半年 | 社区征文
- (pointeur) Écrivez - vous une fonction qui compare la taille de la chaîne et fonctionne comme strcmp.
- Penetration practice - sqlserver empowerment
- Smart subway | cloud computing injects wisdom into urban subway transportation
- STM32 external DHT11 display temperature and humidity
- 【微服务|openfeign】使用openfeign远程调用文件上传接口
- The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO
- 01 qemu 启动编译好的镜像 VFS: Unable to mount root fs on unknown-block(0,0)
猜你喜欢

图解网络:什么是热备份路由器协议HSRP?

I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer

【微服务|openfeign】@FeignClient详解

Storage of MySQL database

Penetration practice - sqlserver empowerment

PostgreSQL users cannot create table configurations by themselves

Idea configuration 360zip open by default -- external tools

Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
![[Logitech] m720](/img/bb/44144a1c3907808398c05b3b36962c.png)
[Logitech] m720

1289_ Implementation analysis of vtask suspend() interface in FreeRTOS
随机推荐
Graduation summary
Common methods of threads
Brief explanation of depth first search (with basic questions)
ROS2中CMake编译选项的设置
【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
Pointer array and array pointer
[book club issue 13] packaging format of video files
There is a problem that the package cannot be parsed in the like project
JDBC advanced
透过JVM-SANDBOX源码,了解字节码增强技术原理
Flink学习8:数据的一致性
Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
postgresql 用户不能自己创建表格配置
pytest多进程/多线程执行测试用例
Pytest multi process / multi thread execution test case
网络 - VXLAN
JS实现文字滚动 跑马灯效果
Introduction to asynchronous task capability of function calculation - task trigger de duplication
Restore the subtlety of window position
Flink learning 7: application structure