力扣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;
}
相关推荐
Forget the Dream18 分钟前
Spring AI 2.0 系列(四):Starter 与 OpenAI-compatible:一个不绑死厂商的模型环境
java·人工智能·spring·springai
GoodStudyAndDayDayUp23 分钟前
Mermaid 流程图基础语法
java·服务器·流程图
dadaobusi23 分钟前
学习:noc死锁
java·服务器·前端
Rabitebla24 分钟前
【Linux】文件系统(四):目录、路径解析与 dentry 缓存
linux·数据结构·c++·笔记·学习·算法·缓存
旋风菠萝26 分钟前
ThreadLocalMap 的 key 使用弱引用?
java
圆心角28 分钟前
前端转 Java 全栈:依赖、入口、路由、中间件到底放哪
java·spring boot·后端
kiracrimson36 分钟前
最短路径:Dijkstra 与 Bellman-Ford、Floyd 各自的边界
数据结构·c++·算法·最短路径·c++学习
Rain的Java大神之路37 分钟前
别再背"512+64"了:RAG 分块策略深度剖析,从原理到 Java 生产实现
java·后端·ai编程
hudd66840 分钟前
JavaEE 初阶 - 网络编程(第二部分:网络编程套接字)
java·开发语言·网络·java-ee