其他分享
首页 > 其他分享> > [LeetCode] - 965. 单值二叉树

[LeetCode] - 965. 单值二叉树

作者:互联网

题目

题目链接
在这里插入图片描述

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */

bool isUnivalTree(struct TreeNode* root){

    if (root==NULL)
    {
        return true;
    }
    if (root->left && root->left->val!= root->val)
    {
        return false;
    }

    if (root->right && root->right->val!= root->val)
    {
        return false;
    }

    return isUnivalTree(root->right) && isUnivalTree(root->left);
}

标签:965,right,TreeNode,struct,val,二叉树,return,root,LeetCode
来源: https://blog.csdn.net/zhaozhenyu123/article/details/121239207