力扣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;
}
相关推荐
码熔burning23 分钟前
【MQ篇】RabbitMQ之消费失败重试!
java·分布式·rabbitmq·mq
Haoea!36 分钟前
java-mybatis01
java·数据库·oracle
zandy101138 分钟前
衡石科技:HENGSHI SENSE 数据权限解决方案
java·数据库·科技
学编程的小程1 小时前
Spring MVC深度解析:从原理到实战
java·spring·mvc
每次的天空1 小时前
Android学习总结之扩展基础篇(一)
android·java·学习
多多*1 小时前
非关系型数据库 八股文 Redis相关 缓存雪崩 击穿 穿透
java·开发语言·jvm·数据库·redis·缓存·nosql
songx_991 小时前
算法设计与分析7(贪心算法)
算法
aigonna2 小时前
Kimi 7B 语音转文字
算法
2401_890665862 小时前
免费送源码:Java+ssm+HTML 三分糖——甜品店网站设计与实现 计算机毕业设计原创定制
java·python·微信小程序·html·php·课程设计·android-studio
zuckzhao952 小时前
Spring Security入门学习(一)Helloworld项目
java·学习·spring