当前位置:网站首页>Leetcode 226. flip binary tree
Leetcode 226. flip binary tree
2022-07-24 22:02:00 【LuZhouShiLi】
Leetcode 226. Flip binary tree
subject
Give you the root node of a binary tree root , Flip this binary tree , And return its root node .
Ideas
- The first sequence traversal , First swap the left and right child nodes
- Then recursively exchange left and right subtrees
Code
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
// Recursive export
if(root == NULL) return root;
// The first sequence traversal First swap the left and right child nodes Then flip the left subtree and the right subtree
swap(root->left,root->right);
invertTree(root->left);
invertTree(root->right);
return root;
}
};
边栏推荐
- 2022牛客多校7.23
- 【南瓜书ML】(task4)神经网络中的数学推导
- @typescript-eslint/ [email protected]
- Machine learning kmeans
- Wechat applet monitoring real-time geographical location change event interface application
- [combination of classes (define a class in a class)]
- 小程序地理位置接口申请
- 腾讯+360+搜狗校招笔试题+知识点总结
- 2022 Tsinghua summer school notes L1_ NLP and bigmodel Foundation
- ESP32C3 LED PWM使用和ESP32差异说明
猜你喜欢

使用frp实现内网穿透

【考研词汇训练营】Day 12 —— native,separate,figure,contribute,species,assumption,suppose

ESP32C3 LED PWM使用和ESP32差异说明

Both Chen Chunhua and Mo Yan have words of suffering
![[image processing] pyefd.elliptic_ fourier_ How descriptors are used](/img/72/d2c825ddd95f541b37b98b2d7f6539.png)
[image processing] pyefd.elliptic_ fourier_ How descriptors are used

91. (leaflet chapter) leaflet situation plotting - offensive direction drawing

Ch single database data migration to read / write separation mode
![Leetcode: the shortest dice sequence impossible to get [thinking questions + grouping ideas]](/img/89/0789cd381302237a28f3f18b3bfa74.png)
Leetcode: the shortest dice sequence impossible to get [thinking questions + grouping ideas]

01_ UE4 advanced_ PBR material

Gradle 学习 ----Gradle 进阶说明
随机推荐
Volcano engine releases cloud growth solutions for six industries
Use of templates
Using gcc to avoid stack smash attack
Principle of an automatic nine point calibration tool (including part of the source code)
[pyspark foundation] row to column and column to row (when there are more than one column)
Metauniverse: technological evolution, industrial ecology and big country game
"Paper reproduction" bidaf code implementation process (4) model training + verification
"Iruntime": undeclared identifier
None of the most complete MySQL commands in history is applicable to work and interview (supreme Collection Edition)
How to gracefully realize regular backup of MySQL database (glory Collection Edition)
With this PDF, I successfully got offers from ant, jd.com, Xiaomi, Tencent and other major manufacturers
Clever use of sort (list & lt; T & gt;, comparator & lt;? Super T & gt;) comparator
leetcode:不可能得到的最短骰子序列【思维题 + 分组思想】
深入理解事务
Gradle learning - integration of gradle and idea
Class notes (4) (3) -573. Lecture hall arrangement (Hall)
Mysql database commands
Feeding Program Source Code to ZK VMs
Unity & facegood audio2face drives face blendshape with audio
运动控制如何位置同步输出