2022年11月15日 星期二

[965] Univalued Binary Tree

令人心情好的題目XD
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool check(struct TreeNode* root, int val){
if (root== NULL)
return true;
if (root->val != val)
return false;
return (check(root->left,val) && check(root->right,val));
}
bool isUnivalTree(struct TreeNode* root){
return check (root, root->val);
}

沒有留言:

張貼留言