力扣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;
}
相关推荐
大模型码小白5 小时前
在 Windows 下 Codex 安装、配置与使用详细指南
java·人工智能·windows
Gauss松鼠会5 小时前
【GaussDB】GaussDB锁阻塞源头查询
java·开发语言·前端·数据库·算法·gaussdb·经验总结
oier_Asad.Chen5 小时前
【洛谷题解/AcWing题解】洛谷P4011 孤岛营救问题/AcWing1131拯救大兵瑞恩
数据结构·笔记·学习·算法·动态规划·图论·宽度优先
mingo_敏5 小时前
DeepAgents : 后端(Backends)
java·开发语言
霸道流氓气质5 小时前
SpringBoot中事务内同步处理 + 事务后异步调用外部系统的通用模式示例
java·spring boot·后端
霸道流氓气质5 小时前
Spring 事务传播机制与 REQUIRES_NEW
java·数据库·spring
BerryS3N6 小时前
Java 后端转型大模型:Demo 能跑不等于能上线
java·人工智能·python·java后端·spring ai·langchain4j·大模型转型
冻柠檬飞冰走茶6 小时前
PTA基础编程题目集 7-19 支票面额(C语言实现)
c语言·开发语言·数据结构·算法
心机之蛙qee6 小时前
Docker Compose 多容器编排
java·docker·容器
船漏了就会沉6 小时前
状态压缩DP:小数据下的“暴力美学”
算法