aboutsummaryrefslogtreecommitdiff
path: root/other/binary_tree_pruning.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/binary_tree_pruning.cpp')
-rw-r--r--other/binary_tree_pruning.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/other/binary_tree_pruning.cpp b/other/binary_tree_pruning.cpp
new file mode 100644
index 0000000..3bac07d
--- /dev/null
+++ b/other/binary_tree_pruning.cpp
@@ -0,0 +1,15 @@
+#include "leetcode.h"
+
+class Solution {
+public:
+ TreeNode *pruneTree(TreeNode *root) {
+ if (root) {
+ root->left = pruneTree(root->left);
+ root->right = pruneTree(root->right);
+ if (root->left || root->right || root->val != 0)
+ return root;
+ }
+ delete root;
+ return nullptr;
+ }
+};