当前位置:网站首页>226. Flip binary tree DFS method
226. Flip binary tree DFS method
2022-07-25 03:37:00 【Mr Gao】
226. Flip binary tree
Give you the root node of a binary tree root , Flip this binary tree , And return its root node .
Example 1:
Input :root = [4,2,7,1,3,6,9]
Output :[4,7,2,9,6,3,1]
Example 2:
Input :root = [2,1,3]
Output :[2,3,1]
Example 3:
Input :root = []
Output :[]
This problem seems very complicated , It's actually very simple , Let's just do it according to the rules :
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */
void dfs(struct TreeNode* root){
if(root){
struct TreeNode* t;
t=root->left;
root->left=root->right;
root->right=t;
dfs(root->left);
dfs(root->right);
}
}
struct TreeNode* invertTree(struct TreeNode* root){
dfs(root);
return root;
}
边栏推荐
- Take a database statement note: when the field is empty, assign the default value to the result
- Lombok detailed introduction
- Sword finger offer II 041. Average value of sliding window_____ Using queue / loop array implementation
- [kaggle] how to effectively avoid oom and the long process of alchemy
- Operations in shell
- Leetcode.745. prefix and suffix search____ Double dictionary tree + double pointer
- Experience sharing of system architecture designers in preparing for the exam: how to prepare for the exam effectively
- Deep learning Titanic (beginner) kaggle Liu er's homework Lesson 8
- NVM installation and use
- C language writes a circular advertising lantern or changes it to a confession system
猜你喜欢

Openlayers draw circles and ellipses

How is the virtual DOM different from the actual DOM?

Direct insert sort / Hill sort

Image processing based on hog feature

Task02 | EDA initial experience

How chemical enterprises choose digital service providers with dual prevention mechanism

B. Making Towers

Lombok detailed introduction

The relationship between private domain traffic and fission marketing. What is super app? Can our enterprise own it?

From input URL to page presentation
随机推荐
10. 509 Certificate (structure + principle)
Import and export using poi
Unified return data format
Moveit2 - 10.urdf and SRDF
Solve mysql5.6 database specified key was too long; Max key length is 767 bytes
Sword finger offer II 041. Average value of sliding window_____ Using queue / loop array implementation
Fiddler grabs packets and displays err_ TUNNEL_ CONNECTION_ FAILED
Recursive and non recursive methods are used to realize the first order, middle order and second order traversal of binary tree respectively
Vscode copy synchronization plug-in expansion
Force deduction brush question 14. Longest common prefix
04 -- two ways of writing el and data
MIM command
C language writes a circular advertising lantern or changes it to a confession system
Li Kou 343 integer partition dynamic programming
Openlayers draw circles and ellipses
Query the information of students whose grades are above 80
Network security - comprehensive penetration test -cve-2018-10933-libssh maintain access
Table of contents of force deduction questions
Image processing based on hog feature
Swagger key configuration items