/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool _isUnivalTree(struct TreeNode* root,int val)
{
if(NULL == root)
return true;
// val是否等于root->val
if(root->val != val)
return false;
return _isUnivalTree(root->left,val) && _isUnivalTree(root->right,val);
}
bool isUnivalTree(struct TreeNode* root){
if(root == NULL)
return true;
//获取二叉树根节点的值
int val = root->val;
//调用函数
return _isUnivalTree(root,val);
}