力扣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;
}
相关推荐
Zella折耳根2 小时前
复习篇-常用实用类
java
菜鸡爱玩4 小时前
线性代数矩阵相乘
线性代数·算法·矩阵
devilnumber7 小时前
Java 递归算法 详解 + 核心要点 + 实战运用 + 避坑指南
java·开发语言·算法
asdfg12589639 小时前
JavaBean是什么?怎么理解?有什么用途?
java·开发语言
‎ദ്ദിᵔ.˛.ᵔ₎9 小时前
双指针、滑动窗口、前缀和、二分查找 算法
算法
顾北顾9 小时前
多头注意力机制
人工智能·深度学习·算法
H178535090969 小时前
SolidWorks_基于草图的实体特征20_特征错误排查
算法·3d建模·solidworks
hujinyuan2016010 小时前
2025年12月中国电子学会青少年机器人技术等级考试试卷(二级) 真题+答案
人工智能·算法·机器人
摇滚侠10 小时前
SpringMVC 入门到实战 文件上传 75-77
java·后端·spring·maven·intellij-idea
GIS数据转换器11 小时前
城市排水生命线安全运行监测平台深度解析
java·运维·人工智能·python·安全·数据挖掘·无人机