[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);
}
上一篇:【LeetCode】965. 单值二叉树


下一篇:965. Univalued Binary Tree