Binary Tree Pruning LeetCode solution in C++

1
class Solution {
2
public:
3
TreeNode *pruneTree(TreeNode *root) {
4
if (!root) return NULL;
5
root->left = pruneTree(root->left);
6
root->right = pruneTree(root->right);
7
if (!root->left && !root->right && root->val == 0) return NULL;
8
return root;
9
}
10
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0