力扣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;
}
相关推荐
@卞9 分钟前
高阶数据结构 --- 单调队列
数据结构·c++·算法
q***017725 分钟前
Spring Boot 热部署
java·spring boot·后端
Seven9726 分钟前
SpringCloud 常见面试题(三)
java
H***997627 分钟前
Java虚拟现实案例
java·开发语言·vr
yifengyiyufjq1 小时前
Docker 镜像制作教程
java·docker·node.js
print(未来)1 小时前
元宇宙与人工智能驱动互联网创新应用:沉浸式体验与智能交互实践探索》
leetcode
tuokuac1 小时前
SQL中AND和逗号,的区别
java·数据库·sql
zl9798991 小时前
RabbitMQ-Hello World
java·分布式·rabbitmq
程序员三明治1 小时前
【Spring进阶】Spring IOC实现原理是什么?容器创建和对象创建的时机是什么?
java·后端·spring·ioc·bean生命周期