力扣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;
}
相关推荐
人活一口气16 小时前
Spring Boot与AIGC的完美结合:从零搭建智能内容生成平台
java·spring boot·aigc
像我这样帅的人丶你还18 小时前
Java 后端详解(三):全局异常处理与 JPA 数据库映射
java·后端
NE_STOP18 小时前
vibe Coding -- 小项目实战
java
未秃头的程序猿1 天前
Java 26正式发布!这3个新特性,让代码量直接减半
java·后端·面试
用户298698530141 天前
Word 文档文本查找与替换的 Java 实现方案
java·后端
阿哉1 天前
Nacos 服务发现源码:藏在背后的两套事件机制,90%的人只讲了一半
java
05Kevin1 天前
lk每日冒险题--数据结构6.27
算法
咖啡八杯1 天前
GoF设计模式——命令模式
java·设计模式·架构
AI人工智能_电脑小能手1 天前
【大白话说Java面试题 第125题】【并发篇】第25题:说说 Java 线程的中断机制
java·后端·面试