力扣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 小时前
链接的迷雾:odr、弱符号与静态库的三国杀
android·java·开发语言·c++·人工智能·深度学习·神经网络
abcefg_h3 小时前
链表算法---基本算法操作(go语言版)
算法·链表·golang
小O的算法实验室3 小时前
2022年IEEE TITS SCI2区TOP,基于切线交点和目标引导策略的无人机自主路径规划,深度解析+性能实测
算法·论文复现·智能算法·智能算法改进
007php0074 小时前
大厂深度面试相关文章:深入探讨底层原理与高性能优化
java·开发语言·git·python·面试·职场和发展·性能优化
qq_334466864 小时前
excel VBA应用
java·服务器·excel
E_ICEBLUE4 小时前
快速合并 Excel 工作表和文件:Java 实现
java·microsoft·excel
qq_214803294 小时前
ArcGIS Runtime与GeoTools融合实践:加密SHP文件的完整读写方案
java·安全·arcgis
Mr_Oak4 小时前
【multi-model】moco系列&SimCLR&BEiT
人工智能·深度学习·神经网络·算法·计算机视觉·transformer·对比学习
Juchecar4 小时前
Spring是Java语境下的“最优解”的原因与启示
java·spring·node.js
邪恶喵喵4 小时前
Tomcat和负载均衡
java·tomcat·负载均衡