Guest User

Untitled

a guest
Apr 26th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. /**
  2. * Definition for a binary tree node.
  3. * struct TreeNode {
  4. * int val;
  5. * TreeNode *left;
  6. * TreeNode *right;
  7. * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
  8. * };
  9. */
  10. class Solution {
  11. public:
  12. TreeNode* pruneTree(TreeNode* root) {
  13. if (!root) return root;
  14. root->left = pruneTree(root->left);
  15. root->right = pruneTree(root->right);
  16. if (root->val == 1 || root->left || root->right)
  17. return root;
  18. delete root;
  19. return nullptr;
  20. }
  21. };
Add Comment
Please, Sign In to add comment