Here is the code for you to see directly, however, there are a few points.
1. in the second ‘if’ clause, note the existence of the root node
2. Once there is at least one false value among the serval judgment values, the result after the && operation is false.
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;
bool a = isUnivalTree(root->left) && isUnivalTree(root->right);
return a;
}