*Leetcode 814. Binary Tree Pruning

Posted Z-Pilgrim

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了*Leetcode 814. Binary Tree Pruning相关的知识,希望对你有一定的参考价值。

https://leetcode.com/problems/binary-tree-pruning/description/

/**
 * Definition for a binary tree node.
 * struct TreeNode 
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) 
 * ;
 */
class Solution 
public:
    TreeNode* pruneTree(TreeNode* root) 
        if (!root) return NULL;
        root->left = pruneTree(root->left);
        root->right = pruneTree(root->right);
        if (!root->left && !root->right && !root->val) return NULL;
        return root;
    
;

 

 

以上是关于*Leetcode 814. Binary Tree Pruning的主要内容,如果未能解决你的问题,请参考以下文章

leetcode814 Binary Tree Pruning

[树] leetcode 814 Binary Tree Pruning

Leetcode 814. 二叉树剪枝

LeetCode 110. Balanced Binary Tree

leetcode 94. Binary Tree Inorder Traversal

99. Recover Binary Search Tre