力扣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;
}
相关推荐
用户35218024547543 分钟前
当 Prompt 学会"热更新":Spring Boot × Nacos3 AI 实战
java·spring boot·ai编程
vivo互联网技术1 小时前
CVPR 2026 | 全新强化学习框架 BeautyGRPO:重塑真实人像
算法·大模型·cvpr·影像
Darling噜啦啦2 小时前
列表转树算法深度解析:从 Map 到 Reduce 的两种实现,面试高频考点
数据结构·算法·面试
东坡白菜4 小时前
破局全栈:一个前端开发的Java入门实战记录(1)
java·全栈
唐青枫4 小时前
Java Tomcat 实战指南:从 Servlet 容器到 Spring Boot 部署
java
wsaaaqqq4 小时前
roudan:自由选择实体、灵活操作数据、快速写入数据库的 Java 框架
java
用户497863050735 小时前
(一)小红的数组操作
算法·编程语言
怕浪猫8 小时前
Electron 系列文章封面图
算法·架构·前端框架
plainGeekDev8 小时前
null 判断 → Kotlin 可空类型
android·java·kotlin
糖拌西瓜皮8 小时前
Java开发者视角:深入理解Node.js异步编程模型
java·后端·node.js