力扣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 分钟前
5.Hash 【由浅入深-redis】
redis·算法·哈希算法
Nuanyt6 分钟前
LeetCode Hot 100 · 双指针 3 题 Java
java·笔记·算法·leetcode·双指针
Wang's Blog12 分钟前
Java 项目实战: 交友项目 - 圈子互动
java·开发语言·交友
Rain的Java大神之路14 分钟前
北漂 13 年,我把 Java 家底钉成了这张知识图谱(全站免费)
java·后端·程序员
wuminyu36 分钟前
JVM规范学习总结-Class文件结构
java·linux·c语言·jvm·c++
七夜zippoe1 小时前
Spring AI + Ollama 本地模型:数据不出内网的合规方案(落地全流程)
java·人工智能·spring·ai·ollama
Wang's Blog1 小时前
Java 项目实战: 交友项目 - 查询单条动态:动态详情页的接口与实现
java·开发语言·交友
yuniko-n1 小时前
【JUC】CAS
java·开发语言
captain3761 小时前
Spring Web MVC(2)
java·前端·spring boot·后端·spring·mvc
志起计算机编程1 小时前
Clickhouse的几个关键优势
算法