当前位置:网站首页>Leetcode exercise 1 - binary tree pruning
Leetcode exercise 1 - binary tree pruning
2022-07-22 15:27:00 【But the sky is cold_ Good autumn】
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* pruneTree(TreeNode* root) {
if(nullptr == root) {
return nullptr;
}
root->left = pruneTree(root->left);
root->right = pruneTree(root->right);
if(nullptr == root->left && nullptr == root->right && 0 == root->val) {
return nullptr;
}
return root;
}
};
边栏推荐
- MySQL Exercise one database Knowledge
- Waiting insurance compliance 2022 series | what should you know about waiting insurance this year?
- 对原数组有影响的几个方法
- Codeworks 5 questions per day (average 1500) - day 22
- one billion two hundred and thirty-four million five hundred and fifty-six thousand six hundred and sixty-six
- Let security move | no matter what industry network architecture, these six tactics win the target
- 如何用一手数据可视化获得老板的青睐,抓住数据可视化关键点
- 【C语言-文件】数据终于可以出内存,到外面的世界看看了/(ㄒoㄒ)/~~
- Redis高可用原理 主从哨兵集群
- Architecture design scheme (continuously updating ing)
猜你喜欢
harbor+trivy的安装使用——筑梦之路
Redis master-slave replication
Open source demo | release of open source example of arcall applet
visual studio踩坑记录
Delete Nan points in 3D point cloud TXT file
Redis持久化(RDB和AOF)
时序数据库
Paper reading | point voxel CNN for efficient 3D deep learning
Record online double write failure log MySQL error troubleshooting reasons
Redis的拓展方案
随机推荐
AIDL示例
How to use first-hand data visualization to win the favor of the boss and grasp the key points of data visualization
指数滑动平均法_百度百科
NFC Introduction (2)
Waiting insurance compliance 2022 series | what should you know about waiting insurance this year?
[Huawei machine test questions] maximum number of components [2022 Q3 | 100 points]
Redis使用Jedis操作
[cloud native kubernetes] jobs and cronjobs management under kubernetes cluster
A simple inventory management system source code
OUU益生菌精耕胃肠健康,获奖天猫国际微生态创新大会
Graffiti Wi Fi & ble SoC development slide strip (6) -- slide strip function demonstration
Wechat applet Decompilation
Voting cannot be repeated
Distributed link tracking skywalking Foundation
涂鸦Wi-Fi&BLE SoC开发幻彩灯带(5)----烧录授权
如何正确使用电流探头
电流探头应该如何选择
第3章——创建与维护MySQL数据表
Redis的拓展方案
加快标准体系建设,促进数据安全产业高质量发展