力扣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;
}
相关推荐
波尔德几秒前
Origin 2024 绘制钟形正态分布曲线:填充颜色并导出透明 PNG
人工智能·算法
Q26433650233 分钟前
【有源码】基于SpringBoot+Vue的博物馆展览与服务一体化平台-java博物馆数字化展品展示与交互平台设计
java·vue.js·spring boot·spring·毕业设计·javaweb·课程设计
guo_wen_qiang8 分钟前
项目使用sentinel遇到的问题
java·sentinel
Omics Pro11 分钟前
微软:多模态生物世界模型
数据库·人工智能·算法·microsoft·机器学习·自然语言处理
CarIise13 分钟前
IDEA与Maven基础课堂笔记
java·intellij-idea·caffe
hai31524754317 分钟前
语言学集合定律
人工智能·算法
小溪学编程19 分钟前
C语言篇:枚举类型
java·c语言·前端
小溪学编程21 分钟前
C语言篇:语言结构
c语言·开发语言·算法
云和数据.ChenGuang28 分钟前
JAVAEE AI工程师路线图
java·人工智能·java-ee·fastapi·springai·langchain4j
2601_9628857228 分钟前
如何用 Python 统计 A 股连续涨停(几连板)?
java·linux·python