【leetcode】单值二叉树

 

bool func(struct TreeNode* node,int val)
{
    if (!node) return true;
    if (node->val != val) return false;
    return func(node->left,val) && func(node->right,val);
}
bool isUnivalTree(struct TreeNode* root){
    if (!root) return false;
    int val = root->val;
    return func(root->left,val) && func(root->right,val);
}

 

posted @ 2020-08-28 10:36  温暖了寂寞  阅读(63)  评论(0编辑  收藏  举报