力扣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;
}
相关推荐
dragoooon342 分钟前
[C++——lesson29.数据结构进阶——「AVL树」]
算法
碧海银沙音频科技研究院7 分钟前
论文写作word插入公式显示灰色解决办法
人工智能·深度学习·算法
Mr_Xuhhh9 分钟前
第一部分:类和对象(中)— 取地址运算符重载
java·开发语言
Selegant12 分钟前
告别传统部署:用 GraalVM Native Image 构建秒级启动的 Java 微服务
java·开发语言·微服务·云原生·架构
__万波__17 分钟前
二十三种设计模式(十三)--模板方法模式
java·设计模式·模板方法模式
动亦定17 分钟前
微服务中如何保证数据一致性?
java·数据库·微服务·架构
长沙京卓20 分钟前
【无人机算法】低空经济下无人机巡检检测识别算法(城市、林业、水利)
算法·无人机
hn小菜鸡22 分钟前
LeetCode 1971.寻找图中是否存在路径
算法·leetcode·职场和发展
王桑.23 分钟前
Spring中IoC的底层原理
java·后端·spring