力扣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;
}
相关推荐
朦胧之6 小时前
AI 编程-老项目改造篇
java·前端·后端
kisshyshy10 小时前
🍦 雪糕、食堂、火车厢:三幅漫画吃透栈、队列与链表
javascript·算法
程序猿大帅10 小时前
别再只当调包侠了:用 Spring AI 落地 Function Calling,我被大模型硬生生砸出了三个大坑
java
程序员晓琪11 小时前
约定大于配置:基于 Java 包名自动生成 API 版本路由的最佳实践
java·spring boot·后端
Flittly11 小时前
【AgentScope Java新手村系列】(11)中断与恢复
java·spring boot·spring
众少成多积小致巨12 小时前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
东坡白菜12 小时前
破局全栈:前端开发的Java入门实战记录—JPA(2)
java·后端
猿人谷17 小时前
不只是 CPU 阈值:STAR 如何用 GAT + Transformer 做容器级自动扩缩容?
人工智能·算法
SimonKing18 小时前
艹,维护AI写的代码,我心态崩了......
java·后端·程序员
用户2986985301419 小时前
Java Word 文档样式进阶:段落与文本背景色设置完全指南
java·后端