力扣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 分钟前
Python入门篇【文件处理】
android·java·python
Java 码农20 分钟前
RabbitMQ集群部署方案及配置指南03
java·python·rabbitmq
Learn Beyond Limits21 分钟前
解构语义:从词向量到神经分类|Decoding Semantics: Word Vectors and Neural Classification
人工智能·算法·机器学习·ai·分类·数据挖掘·nlp
哈库纳玛塔塔25 分钟前
放弃 MyBatis,拥抱新一代 Java 数据访问库
java·开发语言·数据库·mybatis·orm·dbvisitor
你怎么知道我是队长1 小时前
C语言---typedef
c语言·c++·算法
S***q3771 小时前
Spring Boot管理用户数据
java·spring boot·后端
天“码”行空2 小时前
java面向对象的三大特性之一多态
java·开发语言·jvm
毕设源码-郭学长2 小时前
【开题答辩全过程】以 基于SpringBoot框架的民俗文化交流与交易平台的设计与实现为例,包含答辩的问题和答案
java·spring boot·后端
Qhumaing2 小时前
C++学习:【PTA】数据结构 7-1 实验7-1(最小生成树-Prim算法)
c++·学习·算法
好大哥呀2 小时前
Java Web的学习路径
java·前端·学习