mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
17 lines
345 B
C
17 lines
345 B
C
bool isUnivalTree(struct TreeNode *root)
|
|
{
|
|
if (root == NULL)
|
|
return 1;
|
|
if (root->left)
|
|
{
|
|
if (root->left->val != root->val)
|
|
return 0;
|
|
}
|
|
if (root->right)
|
|
{
|
|
if (root->right->val != root->val)
|
|
return 0;
|
|
}
|
|
return isUnivalTree(root->left) && isUnivalTree(root->right);
|
|
}
|