G2A Many GEOs
SHARE
TWEET

Binary Tree Pruning

a guest Apr 8th, 2020 92 in 317 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Definition for a binary tree node.
  3.  * struct TreeNode {
  4.  *     int val;
  5.  *     struct TreeNode *left;
  6.  *     struct TreeNode *right;
  7.  * };
  8.  */
  9.  
  10.  
  11. struct TreeNode* pruneTree(struct TreeNode* root){
  12.     if(!root)
  13.         return NULL;
  14.     root->left = pruneTree(root->left);
  15.     root->right = pruneTree(root->right);
  16.    
  17.     if(root->val == 0 && !root->left && !root->right)
  18.         return NULL;
  19.     return root;
  20. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top