力扣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;
}
相关推荐
山登绝顶我为峰 3(^v^)31 小时前
C/C++ 交叉编译方法
java·c语言·c++
一叶飘零_sweeeet1 小时前
Codex 与 Claude Code 深度拆解:两代 AI 编程智能体的技术本质与 Java 实战指南
java·ai·codex·claude code
Listen·Rain2 小时前
提示词和提示词模板
java·人工智能·spring boot
还有多久拿退休金2 小时前
让飞书知识库跟着 commit 自己长:一套自动化知识库的真实实现
前端·算法·架构
wuqingshun3141592 小时前
重写equals而不重写hashCode,会出什么问题?
java·开发语言
我今晚不熬夜2 小时前
Java语言实现Modbus协议通过用串口读取数据(以RTU为例)
java·网络协议
小锋java12343 小时前
Maven 4 要来了:15 年后,Java 构建工具迎来"彻底重构"
java·maven
KaMeidebaby3 小时前
卡梅德生物技术快报|小 RNA 适配体合成 + 多方法亲和力表征全流程标准化操作手册
前端·网络·数据库·人工智能·算法
是Dream呀3 小时前
基于深度学习的人类行为识别算法研究
人工智能·深度学习·算法