当前位置:网站首页>Leetcode 226 flip binary tree (recursive)
Leetcode 226 flip binary tree (recursive)
2022-07-27 16:14:00 【w ͏ l ͏ j ͏】
The difficulty is simple 573
Turn over a binary tree .
Example :
Input :
4 / \ 2 7 / \ / \ 1 3 6 9Output :
4 / \ 7 2 / \ / \ 9 6 3 1
Ideas : Just flip recursively , Flip the root first , Then flip the left subtree , Then flip the right subtree .
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
if(root==NULL){return NULL;}
TreeNode* temp = root->left;
root->left = root->right;
root->right = temp;
invertTree(root->left);
invertTree(root->right);
return root;
}
}; 
边栏推荐
猜你喜欢

Leetcode 226 翻转二叉树(递归)

Openwrt增加对 sd card 支持

webRTC中的coturn服务安装

解决MT7620不断循环uboot(LZMA ERROR 1 - must RESET board to recover)

DRF学习笔记(一):数据序列化

企业运维安全就用行云管家堡垒机!

Excel提取重复项

Addition, deletion, query and modification of MySQL table data

Penetration test - dry goods | 80 + network security interview experience post (interview)
![[sword finger offer] interview question 41: median in data flow - large and small heap implementation](/img/c3/7caf008b3bd4d32a00b74f2c508c65.png)
[sword finger offer] interview question 41: median in data flow - large and small heap implementation
随机推荐
[sword finger offer] interview question 50: the first character that appears only once - hash table lookup
Nacos
Under the ban, the Countermeasures of security giants Haikang and Dahua!
Live broadcast software development, customized pop-up effect of tools
43亿欧元现金收购欧司朗宣告失败!ams表示将继续收购
接连取消安富利/文晔/世平代理权,TI到底打的什么算盘?
Rare bitwise operators
Samsung closes its last mobile phone factory in China
多行文本溢出打点
三星关闭在中国最后一家手机工厂
[sword finger offer] interview question 42: the maximum sum of continuous subarrays -- with 0x80000000 and int_ MIN
QT (VI) value and string conversion
TSMC's counterattack: it accused lattice core of infringing 25 patents and asked for prohibition!
Axure 安装图标字体元件库
解决openwrt package目录下多个文件夹重名编译警告(call subdir 函数)
leetcode25题:K 个一组翻转链表——链表困难题目详解
: 0xc0000005: an access conflict occurs when writing position 0x01458000 - to be solved
profileapi.h header
vant-ui toast和dialog使用
C语言程序设计(第三版)