力扣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;
}
相关推荐
血色橄榄枝2 小时前
基于用户注册信息的关键词检测挑战赛「Datawhale AI 夏令营」
人工智能·算法·机器学习
Java搬码工3 小时前
CompletableFuture 完整详解 + 全场景使用案例
java
许心月3 小时前
Java学习资料网站汇总
java
c238563 小时前
第二篇:《测试指挥官:可视化单题自测框架(含 assert 实操)》
java·数据库·c++·算法·安全性测试
帅次4 小时前
Kotlin 与 Java 互操作:混合工程里的平台类型与 API 边界
java·开发语言·kotlin·suspend·nullable
六点_dn4 小时前
Linux学习笔记-printf命令
linux·运维·算法
X-⃢_⃢-X4 小时前
一、第一阶段:认识 Spring Boot
java·spring boot·后端
前端工作日常4 小时前
我学习到的Java程序的生命周期
java·后端
SunnyDays10115 小时前
Java 实现 PDF 页面删除、排序、旋转和裁剪
java·pdf
遥感知识服务5 小时前
Sentinel-1 + DEM + FwDET + 随机森林:从快速水深初估到多因子误差修正
算法·随机森林·sentinel