当前位置:网站首页>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;
}
}; 
边栏推荐
- 使用transform:translate()出现内容模糊问题
- To meet risc-v challenges? ARM CPU introduces custom instruction function!
- 借5G东风,联发科欲再战高端市场?
- Ncnn reasoning framework installation; Onnx to ncnn
- mysql设置密码时报错 Your password does not satisfy the current policy requirements(修改·mysql密码策略设置简单密码)
- [sword finger offer] interview question 45: arrange the array into the smallest number
- Solve mt7620 continuous cycle uboot (LZMA error 1 - must reset board to recover)
- Mlx90640 infrared thermal imager temperature sensor module development notes (VII)
- keil 采用 makefile 实现编译
- Oracle 常用语句
猜你喜欢

Text capture picture (Wallpaper of Nezha's demon child coming to the world)

First acquaintance with MySQL database

文本截取图片(哪吒之魔童降世壁纸)

Determine the exact type of data

Pychart imports the existing local installation package

drf使用:get请求获取数据(小例子)

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

Nacos

Flask connects to existing tables in MySQL database

Clickhouse 20.x distributed table testing and chproxy deployment (II)
随机推荐
First acquaintance with MySQL database
DRF学习笔记(准备)
Leetcode 226 翻转二叉树(递归)
Solve the compilation warning of multiple folders with duplicate names under the openwrt package directory (call subdir function)
逗号操作符你有用过吗?
DRF学习笔记(三):模型类序列化器ModelSerializer
Multiline text overflow dotting
一款功能强大的Web漏洞扫描和验证工具(Vulmap)
传音控股披露被华为起诉一事:已立案,涉案金额2000万元
借5G东风,联发科欲再战高端市场?
profileapi. h header
These questions~~
Enable shallow and deep copies+
Nacos
Introduction to JWT
Introduction and use of redis
43亿欧元现金收购欧司朗宣告失败!ams表示将继续收购
快速高效删除node_modules
Using Lombok results in the absence of parent class attributes in the printed toString
C语言实现字节流与十六进制字符串的相互转换