mirror of
https://github.com/TheAlgorithms/C
synced 2025-04-22 13:16:14 +03:00
14 lines
334 B
C
14 lines
334 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);
|
|
}
|