当前位置:网站首页>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 .
边栏推荐
- [microservice openfeign] use openfeign to remotely call the file upload interface
- 透过JVM-SANDBOX源码,了解字节码增强技术原理
- JS实现文字滚动 跑马灯效果
- How was my life in 2021
- Katalon中控件的参数化
- Idea configuration 360zip open by default -- external tools
- 02 specific implementation of LS command
- Getting started with the go language is simple: go implements the Caesar password
- 毕业三年,远程半年 | 社区征文
- (指針)自己寫一個比較字符串大小的函數,功能與strcmp類似。
猜你喜欢
[csrf-01] basic principle and attack and defense of Cross Site Request Forgery vulnerability
Penetration practice - sqlserver empowerment
leetcode刷题:二叉树08(N叉树的最大深度)
Flink learning 6: programming model
Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
如何远程办公更有效率 | 社区征文
Unity draws the trajectory of pinball and billiards
透过JVM-SANDBOX源码,了解字节码增强技术原理
Activiti7 task service - process variables (setvariable and setvariablelocal)
'2'>' 10'==true? How does JS perform implicit type conversion?
随机推荐
Restore the subtlety of window position
leetcode刷题:二叉树09(二叉树的最小深度)
毕业总结
Perf simple process for multithreaded profile
Support the first triggered go ticker
线程常用的方法
Huawei cloud Kunpeng engineer training (Guangxi University)
*. No main manifest attribute in jar
Redis cluster uses Lua script. Lua script can also be used for different slots
Katalon framework tests web (XXI) to obtain element attribute assertions
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
hbuildx中夜神模拟器的配置以及热更新
My opinion on how to effectively telecommute | community essay solicitation
leetcode刷题:二叉树04(二叉树的层序遍历)
批处理初识
ctf-pikachu-XSS
Msgraphmailbag - search only driveitems of file types
程序员远程办公喜忧参半| 社区征文
一位毕业生的自我分享
I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer