Delete Leaves With a Given Value Medium

第63天。

水题。

今天的题目是Delete Leaves With a Given Value Medium:

太水了,不解释了。

1
2
3
4
5
6
7
8
9
TreeNode* removeLeafNodes(TreeNode* root, int target) {
if (root == nullptr) return nullptr;
root->left = removeLeafNodes(root->left, target);
root->right = removeLeafNodes(root->right, target);
if (!root->left && !root->right && target == root->val)
return nullptr;
else
return root;
}