力扣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;
}
相关推荐
霸道流氓气质17 分钟前
通义千问 VL & Audio:图像、视频、语音多模态 Java 集成深度解析
java·开发语言·音视频
lemon_sjdk20 分钟前
WCPoint、WebPageClient和Accessor类源码
java·安全·webkit·javafx
vx-Biye_Design21 分钟前
springboot中国传统节日宣传平台49078-计算机课程设计、毕业设计
java·前端·vue.js·spring boot·后端·课程设计·idea
野生技术架构师33 分钟前
从向量检索到混合搜索优化:Spring AI 2.0.1 + pgvector RAG 实战
java·人工智能·spring
橘子汽水1681 小时前
Leetcode 198,118打家劫舍,杨辉三角
算法·leetcode
IT枫斗者枫哥1 小时前
CompletableFuture 超时了,任务还在跑?用三个实验分清超时与取消
java
LuminousCPP1 小时前
数据结构-排序(三):快速排序进阶|挖坑法、双指针交换与手动栈非递归实现
c语言·数据结构·笔记·算法·排序算法
chushiyunen1 小时前
mockito笔记
java·开发语言·笔记
Doubbbbbbble云1 小时前
基于空间局部性的排序算法性能重构思路4
java·重构·排序算法
MetaLite2 小时前
Java 时间处理的两个坑:单位误判,半秒算成一秒
java·开发语言·前端