力扣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 小时前
BcoreOS安全通信架构:FsSession 抗算法后门安全设计
算法·安全·架构
金銀銅鐵5 小时前
带您看懂字节码指令(二):空循环里有什么
java·后端·ai编程
吴名氏.7 小时前
Java转AI Agent教程(第十三周)混合检索与重排
java·数据库·人工智能·ai·ai agent
.痞老板.8 小时前
java ee--多线程(进阶)
java·java-ee
深入云栈9 小时前
Netty 4.2.x 源码深度解析 (二十三):ByteBuf 核心设计 —— 索引、类型与零拷贝
java·后端·架构
唐墨1239 小时前
linux kernel 比较数据大小的宏定义
linux·算法
拂拉氏10 小时前
【知识讲解-题目讲解】 统计满足K约束的子字符串数量2 (滑动窗口+前缀和+二分查找+分析)
算法·前缀和·二分查找·滑动窗口
wang_shu_mo_ran10 小时前
MyBatis 从入门到进阶(一)
java·spring·mybatis
量化分析码农12 小时前
股票历史数据的复权参数对照:多级别返回的字段与数值差异
java·javascript·后端