力扣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;
}
相关推荐
崎岖Qiu5 分钟前
【设计模式笔记19】:建造者模式
java·笔记·设计模式·建造者模式
SUPER52663 小时前
本地开发环境_spring-ai项目启动异常
java·人工智能·spring
moxiaoran57533 小时前
Spring AOP开发的使用场景
java·后端·spring
小王师傅668 小时前
【轻松入门SpringBoot】actuator健康检查(上)
java·spring boot·后端
醒过来摸鱼8 小时前
Java classloader
java·开发语言·python
专注于大数据技术栈8 小时前
java学习--StringBuilder
java·学习
loosenivy8 小时前
企业银行账户归属地查询接口如何用Java调用
java·企业银行账户归属地·企业账户查询接口·企业银行账户查询
IT 行者8 小时前
Spring Security 6.x 迁移到 7.0 的完整步骤
java·spring·oauth2
JIngJaneIL9 小时前
基于java+ vue农产投入线上管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
东东的脑洞9 小时前
【面试突击二】JAVA基础知识-volatile、synchronized与ReentrantLock深度对比
java·面试