本文主要是介绍力扣965 单值二叉树,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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;
}
这篇关于力扣965 单值二叉树的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!