力扣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;
}
相关推荐
AgentMaster12 小时前
企业如何应用智能客服?5 个典型场景的技术架构与实施路径
大数据·算法
宁渡AI大模型12 小时前
AI 全栈面试新趋势:Vibe Coding、前端、Java 后端高频面试题深度解析|河南宁渡科技有限公司编程教程
java·javascript·人工智能·python·ai大模型
CallFay云起未来12 小时前
AI客服如何与人工客服协同?从任务路由到上下文交接的Agent架构实践
java·人工智能·文心一言
cfm_291412 小时前
观察者模式
java
程曦曦13 小时前
MySQL 生产库误删 98 张表后的时间点恢复实战:从 binlog 解析到资金对账
linux·数据结构·其他·算法·ubuntu·运维开发
野生技术架构师13 小时前
1000+ Java面试题知识图谱:从基础语法到分布式架构的完整拓扑
java·面试
步行cgn13 小时前
Spring 底层如何创建对象:反射机制与实例化策略
java·后端·spring
何以解忧,唯有..13 小时前
Redis 过期事件监听:原理与实战
java
weixin_3077791313 小时前
C++代码实现MATLAB中的ode45函数功能
开发语言·c++·算法·matlab
风中的小熊生气13 小时前
Spring Boot 面试知识(二):分层、IoC、异常、配置与 Redis
java·springboot