当前位置:网站首页>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 .
边栏推荐
- The new data center helps speed up the construction of a digital economy with data as a key element
- Graduation summary
- Pytest multi process / multi thread execution test case
- Distributed system: what, why, how
- LevelDB源码解读-SkipList
- "Implement both software and hardware" to help build a new cloud computing data center
- 图解网络:什么是热备份路由器协议HSRP?
- 10 reasons for not choosing to use free virtual hosts
- ROS2中CMake编译选项的设置
- DP83848+网线热拔插
猜你喜欢

dried food! Generation of rare samples based on GaN

10 reasons for not choosing to use free virtual hosts

如何有效远程办公之我见 | 社区征文

如何远程办公更有效率 | 社区征文

Brief explanation of depth first search (with basic questions)

Tcpclientdemo for TCP protocol interaction

There is a problem that the package cannot be parsed in the like project

Mitsubishi M70 macro variable reading Mitsubishi M80 public variable acquisition Mitsubishi CNC variable reading acquisition Mitsubishi CNC remote tool compensation Mitsubishi machine tool online tool

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

1289_ Implementation analysis of vtask suspend() interface in FreeRTOS
随机推荐
Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
Tcpclientdemo for TCP protocol interaction
(指针)编写函数void fun(int x,int *pp,int *n)
Small record of thinking
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
Msgraphmailbag - search only driveitems of file types
【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
支持首次触发的 Go Ticker
PPt 教程,如何在 PowerPoint 中将演示文稿另存为 PDF 文件?
【webrtc】m98 ninja 构建和编译指令
User defined path and file name of Baidu editor in laravel admin
线程常用的方法
(指針)自己寫一個比較字符串大小的函數,功能與strcmp類似。
Confession code collection, who says program apes don't understand romance
How to add custom API objects in kubernetes (1)
mysql数据库的存储
Rhcsa-- day one
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
'2'>' 10'==true? How does JS perform implicit type conversion?
laravel admin里百度编辑器自定义路径和文件名