力扣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 小时前
AI时代:DDD领域驱动建模与Ontology语义建模的区别
java·设计模式·架构
jeffer_liu5 小时前
Spring AI 生产级实战:工具调用
java·人工智能·后端·spring·ai编程
比昨天多敲两行6 小时前
linux 线程概念与控制
java·开发语言·jvm
8Qi86 小时前
LeetCode 75:颜色分类(荷兰国旗问题)—— Java 题解 ✅
java·算法·leetcode·指针·排序
zzhongcy6 小时前
@Transactional 同类内部调用失效 + 两种自代理解决方案
java
AutumnWind04206 小时前
【Intelij IDEA使用手册】
java·ide·intellij-idea
888CC++7 小时前
如何在 C 语言中进行程序调试?
前端·javascript·算法
就叫_这个吧8 小时前
Java注解、元注解、自定义注解定义及应用
java·开发语言·注解
Sam_Deep_Thinking8 小时前
聊聊Java中的of
java·开发语言·架构